Merged revisions 53075 via svnmerge from

http://svn.silverstripe.com/open/modules/sapphire/branches/2.2.2

........
  r53075 | sminnee | 2008-04-21 10:56:46 +1200 (Mon, 21 Apr 2008) | 1 line
  
  Made has_one, has_many, and many_many methods more reliable
........


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53522 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-04-26 06:53:23 +00:00
parent 1bc00f4b2d
commit f427047b9d

View File

@ -1002,16 +1002,10 @@ class DataObject extends ViewableData implements DataObjectInterface {
*/ */
public function has_one($component = null) { public function has_one($component = null) {
$classes = ClassInfo::ancestry($this); $classes = ClassInfo::ancestry($this);
$good = false;
foreach($classes as $class) { foreach($classes as $class) {
// Wait until after we reach DataObject // Wait until after we reach DataObject
if(!$good) { if(in_array($class, array('Object', 'ViewableData', 'DataObject'))) continue;
if($class == 'DataObject') {
$good = true;
}
continue;
}
if($component) { if($component) {
$candidate = eval("return isset({$class}::\$has_one[\$component]) ? {$class}::\$has_one[\$component] : null;"); $candidate = eval("return isset({$class}::\$has_one[\$component]) ? {$class}::\$has_one[\$component] : null;");
@ -1060,16 +1054,9 @@ class DataObject extends ViewableData implements DataObjectInterface {
*/ */
public function has_many($component = null) { public function has_many($component = null) {
$classes = ClassInfo::ancestry($this); $classes = ClassInfo::ancestry($this);
$good = false;
foreach($classes as $class) { foreach($classes as $class) {
// Wait until after we reach DataObject if(in_array($class, array('ViewableData', 'Object', 'DataObject'))) continue;
if(!$good) {
if($class == 'DataObject') {
$good = true;
}
continue;
}
if($component) { if($component) {
$candidate = eval("return isset({$class}::\$has_many[\$component]) ? {$class}::\$has_many[\$component] : null;"); $candidate = eval("return isset({$class}::\$has_many[\$component]) ? {$class}::\$has_many[\$component] : null;");
@ -1096,20 +1083,10 @@ class DataObject extends ViewableData implements DataObjectInterface {
*/ */
public function many_many($component = null) { public function many_many($component = null) {
$classes = ClassInfo::ancestry($this); $classes = ClassInfo::ancestry($this);
$good = false;
foreach($classes as $class) { foreach($classes as $class) {
// Wait until after we reach DataObject // Wait until after we reach DataObject
if(!$good) { if(in_array($class, array('ViewableData', 'Object', 'DataObject'))) continue;
if($class == 'DataObject') {
$good = true;
}
continue;
}
if($class == 'DataObject' || $class == 'ViewableData') {
continue;
}
if($component) { if($component) {
// Try many_many // Try many_many