mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7963 from open-sausages/pulls/4/fix-polymorphic-reciprocal-again
BUG Change inverse polymorphic inference to silent-empty instead of explicit error
This commit is contained in:
commit
1a75a27f17
@ -1884,7 +1884,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
* Notes on behaviour:
|
* Notes on behaviour:
|
||||||
* - This can still be used on components that are defined on both sides, but do not need to be.
|
* - This can still be used on components that are defined on both sides, but do not need to be.
|
||||||
* - All has_ones on remote class will be treated as local has_many, even if they are belongs_to
|
* - All has_ones on remote class will be treated as local has_many, even if they are belongs_to
|
||||||
* - Cannot be used on polymorphic relationships
|
* - Polymorphic relationships do not have two natural endpoints (only on one side)
|
||||||
|
* and thus attempting to infer them will return nothing.
|
||||||
* - Cannot be used on unsaved objects.
|
* - Cannot be used on unsaved objects.
|
||||||
*
|
*
|
||||||
* @param string $remoteClass
|
* @param string $remoteClass
|
||||||
@ -1911,14 +1912,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$remoteRelation
|
$remoteRelation
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
// If relation is polymorphic, do not infer recriprocal relationship
|
||||||
if ($class === self::class) {
|
if ($class === self::class) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
return null;
|
||||||
"%s cannot generate opposite component of relation %s.%s as it is polymorphic. " .
|
|
||||||
"This method does not support polymorphic relationships",
|
|
||||||
__METHOD__,
|
|
||||||
$remoteClass,
|
|
||||||
$remoteRelation
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
if (!is_a($this, $class, true)) {
|
if (!is_a($this, $class, true)) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
@ -1950,14 +1946,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$relationType,
|
$relationType,
|
||||||
$polymorphic
|
$polymorphic
|
||||||
);
|
);
|
||||||
|
// If relation is polymorphic, do not infer recriprocal relationship automatically
|
||||||
if ($polymorphic) {
|
if ($polymorphic) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
return null;
|
||||||
"%s cannot generate opposite component of relation %s.%s, as the other end appears" .
|
|
||||||
"to be a has_one polymorphic. This method does not support polymorphic relationships",
|
|
||||||
__METHOD__,
|
|
||||||
$remoteClass,
|
|
||||||
$remoteRelation
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
$joinID = $this->getField($joinField);
|
$joinID = $this->getField($joinField);
|
||||||
if (empty($joinID)) {
|
if (empty($joinID)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user