March 2019
Intermediate to advanced
394 pages
11h 4m
English
Modeling one-to-one and one-to-many relationships can be done via annotations, YAML, or XML. Using annotations, we can define multiple embedded sub-documents within our document, as shown in the following example:
/** @Document */class User{ // ... /** @EmbedMany(targetDocument="Phonenumber") */ private $phonenumbers = array(); // ...}/** @EmbeddedDocument */class Phonenumber{ // ...}
Here, a User document embeds many phonenumbers. @EmbedOne() will embed one sub-document to be used for modeling one-to-one relationships.
Referencing is similar to embedding, as shown in the following example:
/** @Document */class User{ // ... /** * @ReferenceMany(targetDocument="Account") */ private $accounts = array(); // ...}Read now
Unlock full access