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:
Loz Calver 2018-03-29 09:03:03 +01:00 committed by GitHub
commit 1a75a27f17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)) {