Add Failing Test Case for Invalid Bidirectional Association Mapping with Mapped Superclass in Class Hierarchy#9517
Closed
bobdercole wants to merge 2 commits intodoctrine:2.11.xfrom
Closed
Conversation
Contributor
|
Is this related to #8415 somehow? |
Contributor
Author
|
Yes! The inheritance hierarchy you have defined is the same as mine. /**
* @Entity
*/
class GH9516Passenger
{
/**
* @var int $id
* @Id
* @Column(type="integer")
*/
private $id;
/**
* @var GH9516Vehicle $vehicle
* @ManyToOne(targetEntity="GH9516Vehicle", inversedBy="passengers")
*/
private $vehicle;
}
/**
* @Entity
*/
abstract class GH9516Vehicle
{
/**
* @var int $id
* @Id
* @Column(type="integer")
*/
private $id;
/**
* @var GH9516Passenger[] $passengers
* @OneToMany(targetEntity="GH9516Passenger", mappedBy="vehicle")
*/
private $passengers;
}
/**
* @MappedSuperclass
*/
abstract class GH9516Car extends GH9516Vehicle
{
}
/**
* @Entity
*/
class GH9516SportsCar extends GH9516Car
{
}The big difference is the association. Mine defines a one-to-many bidirectional relationship on the base class. My issue occurs when validating the mapping; an exception is thrown. Your fix almost solves this issue. My test cases passes if I add your extra condition to the illegal association on mapped superclass check, like so: if ($parentClass->isMappedSuperclass) {
if ($mapping['type'] & ClassMetadata::TO_MANY && ! $mapping['isOwningSide'] && ! isset($mapping['inherited'])) {
throw MappingException::illegalToManyAssociationOnMappedSuperclass($parentClass->name, $field);
}
if (! isset($mapping['inherited'])) {
$mapping['sourceEntity'] = $subClass->name;
}
} |
mpdude
added a commit
to mpdude/doctrine2
that referenced
this pull request
Jan 24, 2023
…ed superclass in the hierarchy This picks the test case from doctrine#9517 and rebases it onto 2.14.x. The problem has been covered in doctrine#8415, so this PR closes doctrine#9517 and fixes doctrine#9516. Co-authored-by: Robert D'Ercole <bobdercole@gmail.com>
mpdude
added a commit
to mpdude/doctrine2
that referenced
this pull request
Jan 24, 2023
…ed superclass in the hierarchy This picks the test case from doctrine#9517 and rebases it onto 2.14.x. The problem has been covered in doctrine#8415, so this PR closes doctrine#9517 and fixes doctrine#9516. Co-authored-by: Robert D'Ercole <bobdercole@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #9516.