mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #2572 from Zauberfisch/api-getRemoteJoinField-enhancement-2570
API: DataObject->getRemoteJoinField() no longer defaults to ParentID but throws an exception instead
This commit is contained in:
commit
ed6e45610f
@ -1532,15 +1532,24 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
if($fieldPos = strpos($remoteClass, '.')) {
|
||||
return substr($remoteClass, $fieldPos + 1) . 'ID';
|
||||
}
|
||||
|
||||
$remoteRelations = array_flip(Config::inst()->get($remoteClass, 'has_one'));
|
||||
|
||||
$remoteRelations = Config::inst()->get($remoteClass, 'has_one');
|
||||
if(!is_array($remoteRelations)) {
|
||||
$remoteRelations = array();
|
||||
}
|
||||
$remoteRelations = array_flip($remoteRelations);
|
||||
|
||||
// look for remote has_one joins on this class or any parent classes
|
||||
foreach(array_reverse(ClassInfo::ancestry($this)) as $class) {
|
||||
if(array_key_exists($class, $remoteRelations)) return $remoteRelations[$class] . 'ID';
|
||||
}
|
||||
|
||||
return 'ParentID';
|
||||
|
||||
$message = "No has_one found on class '$remoteClass'";
|
||||
if($type == 'has_many') {
|
||||
// include a hint for missing has_many that is missing a has_one
|
||||
$message .= ", the has_many relation from '$this->class' to '$remoteClass' requires a has_one on '$remoteClass'";
|
||||
}
|
||||
throw new Exception($message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user