doctrine / mongodb-odm

The Official PHP MongoDB ORM/ODM
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/
MIT License
1.09k stars 504 forks source link

References to embedded document collections #554

Open Bilge opened 11 years ago

Bilge commented 11 years ago

I'm not sure if this is officially supported by Doctrine, since it is not documented, but it works - with an error notice.

For example, if I have documents A and B where document B has an embedded document, E, I can design the mapping as follows:

/** @Document */
class A {
    /** @ReferenceMany(targetDocument="B", mappedBy="foo.bar") */
    private $whatever = [];
}

/** @Document */
class B {
    /** @EmbedMany(targetDocument="E") */
    private $foo = [];
}

/** @EmbeddedDocument */
class E {
     /** @ReferenceOne(targetDocument="A", inversedBy="whatever") */
    private $bar;
}

However, reading A::$whatever generates the following notice:

Notice: Undefined index: foo.bar in mongodb-odm/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php on line 709

Despite this, the document collection is retrieved correctly.

Bilge commented 11 years ago

This doesn't work if class B has a binary ID and $bar is a discriminator reference. I'm not sure what the culprit is here, but the symptomns are that count(A::$whatever) will never be > 1. That is, at most only one item is loaded into the collection on the field with an embedded document mapping.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.

Bilge commented 3 years ago

Imagine thinking anyone cares about design flaws.

alcaeus commented 3 years ago

Imagine thinking anyone cares about Open Source being a joint effort.

Bilge commented 3 years ago

Imagine thinking open source means other people work for you for free.