官术网_书友最值得收藏!

Inheritance with Doctrine

Modeling one-one and one-many relationships can be done via annotations, YAML, or XML. Using annotations, we can define multiple embedded subdocuments within our document:

/** @Document */
class User
{
// ...
/** @EmbedMany(targetDocument="Phonenumber") */
private $phonenumbers = array();
// ...
}
/** @EmbeddedDocument */
class Phonenumber
{
// ...
}

Here a User document embeds many PhoneNumbers. @EmbedOne() will embed one subdocument to be used for modeling one-one relationships.

Referencing is similar to embedding:

/** @Document */
class User
{
// ...
/**
* @ReferenceMany(targetDocument="Account")
*/
private $accounts = array();
// ...
}
/** @Document */
class Account
{
// ...
}

@ReferenceMany() and @ReferenceOne() are used to model one-many and one-one relationships via referencing into a separate collection.

主站蜘蛛池模板: 兰西县| 青河县| 樟树市| 北海市| 宿迁市| 晋中市| 曲阜市| 宿州市| 通渭县| 金溪县| 什邡市| 奉贤区| 恩施市| 英吉沙县| 全州县| 霍山县| 会宁县| 晋中市| 明水县| 平陆县| 崇文区| 临泉县| 张家港市| 江永县| 石首市| 长顺县| 永胜县| 竹山县| 当阳市| 平和县| 鹿邑县| 胶南市| 濉溪县| 缙云县| 雷州市| 龙山县| 富锦市| 壶关县| 拜城县| 靖西县| 若羌县|