Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Failing Test Case for Invalid Bidirectional Association Mapping with Mapped Superclass in Class Hierarchy #9517

Closed

Conversation

bobdercole
Copy link
Contributor

See #9516.

@mpdude
Copy link
Contributor

mpdude commented Feb 17, 2022

Is this related to #8415 somehow?

@bobdercole
Copy link
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants