Skip to content

Commit

Permalink
Throw an exception when the inverse side configures the join column(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Apr 25, 2023
1 parent ba9f51a commit c870020
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Doctrine/ORM/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit c870020

Please sign in to comment.