mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #2616 from Zauberfisch/3.1
Check if remote class exists in DataObject->getRemoteJoinField()
This commit is contained in:
commit
892b772d1c
@ -1528,6 +1528,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
if(!$remoteClass) {
|
||||
throw new Exception("Unknown $type component '$component' on class '$this->class'");
|
||||
}
|
||||
if(!ClassInfo::exists(strtok($remoteClass, '.'))) {
|
||||
throw new Exception(
|
||||
"Class '$remoteClass' not found, but used in $type component '$component' on class '$this->class'"
|
||||
);
|
||||
}
|
||||
|
||||
if($fieldPos = strpos($remoteClass, '.')) {
|
||||
return substr($remoteClass, $fieldPos + 1) . 'ID';
|
||||
@ -1546,8 +1551,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
|
||||
$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'";
|
||||
// include a hint for has_many that is missing a has_one
|
||||
$message .= ", the has_many relation from '$this->class' to '$remoteClass'";
|
||||
$message .= " requires a has_one on '$remoteClass'";
|
||||
}
|
||||
throw new Exception($message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user