简体   繁体   English

教义在三个表之间的多对多关系

[英]Doctrine Many-to-Many relationship between three tables

I have three tables: note , user and tag . 我有三个表: noteusertag Following is the diagram of the relationship between those tables: 以下是这些表之间的关系图:

alt text http://www.ilabs.lt/share/database.jpg 替代文字http://www.ilabs.lt/share/database.jpg

User can have many Notes and Tags , Note can have many Users and Tags , Tag can have many Users and many Notes . 用户可以有很多注释标签注释可以有很多用户标记标签可以有许多用户和很多注释 I have no problem setting many-to-many relationship between two tables, but can't manage to relate three tables. 我在设置两个表之间的多对多关系方面没有问题,但是无法关联三个表。 How can I describe this relationship in Doctrine? 我该如何在学说中描述这种关系?

You should make NoteUserTag its own Record/Entity with an additional surrogate ID: 您应该将NoteUserTag设置为其自己的Record / Entity,并附加一个代理ID:

note_user_tag_id
note_id
user_id
tag_id

This is probably the best to handle this situation. 这可能是处理这种情况的最佳方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM