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

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.

主站蜘蛛池模板: 简阳市| 达拉特旗| 秦皇岛市| 平潭县| 新民市| 汽车| 木里| 沙河市| 黔江区| 玉龙| 佳木斯市| 合作市| 鹿邑县| 同心县| 磴口县| 来安县| 都匀市| 乐陵市| 儋州市| 且末县| 阿鲁科尔沁旗| 瓮安县| 庆安县| 阳山县| 石屏县| 和政县| 拉萨市| 于田县| 巴塘县| 巍山| 永仁县| 永川市| 德格县| 永定县| 舞钢市| 瑞金市| 山东| 济阳县| 天长市| 夏河县| 徐闻县|