- Mastering MongoDB 3.x
- Alex Giamas
- 125字
- 2021-08-20 10:10:53
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.
推薦閱讀
- 樂高創意機器人教程(中級 下冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- CorelDRAW X4中文版平面設計50例
- Pig Design Patterns
- DevOps:Continuous Delivery,Integration,and Deployment with DevOps
- The Python Workshop
- Google SketchUp for Game Design:Beginner's Guide
- Deep Reinforcement Learning Hands-On
- Unity Multiplayer Games
- 精通LabVIEW程序設計
- 寒江獨釣:Windows內核安全編程
- 重估:人工智能與賦能社會
- 數字多媒體技術基礎
- 空間機器人智能感知技術
- Puppet 3 Beginner’s Guide
- ADuC系列ARM器件應用技術