From c870020eb42e6105821c538378811133f7ca471b Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Tue, 25 Apr 2023 10:26:24 +0200 Subject: [PATCH] Throw an exception when the inverse side configures the join column(s) --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 4 ++-- lib/Doctrine/ORM/Mapping/MappingException.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 5d973905e21..5cca36f02c1 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1864,8 +1864,8 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping) { $mapping = $this->_validateAndCompleteAssociationMapping($mapping); - if (isset($mapping['joinColumns']) && $mapping['joinColumns']) { - $mapping['isOwningSide'] = true; + if (isset($mapping['joinColumns']) && $mapping['joinColumns'] && ! $mapping['isOwningSide']) { + throw MappingException::joinColumnNotAllowedOnInverseSide($this->name, $mapping['fieldName']); } if ($mapping['isOwningSide']) { diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index c0a5d1392fe..ef2490dd63e 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -345,6 +345,11 @@ public static function joinColumnMustPointToMappedField($className, $joinColumn) )); } + public static function joinColumnNotAllowedOnInverseSide(string $className, string $fieldName): self + { + return new self(sprintf('The %s#%s field is not the owning side of the association, so it may not configure join column(s)', $className, $fieldName)); + } + /** * @param class-string $className *