简体   繁体   English

如何在Doctrine 1.2中设置用于通过表映射的关系?

[英]How to set relations in Doctrine 1.2 for mapped through table?

Tables: 表格:

tbl_user(id, name)
tbl_group(id, name);
tbl_user_group(user_id, group_id);

If there were all three classes generated User,Group,UserGroup . 如果所有三个类都生成了User,Group,UserGroup How should i setup the relations in User or Group so that they are mapped through the user_group table? 我应该如何在用户或组中设置关系,以便通过user_group表进行映射?

I'm using Doctrine 1.2 我正在使用Doctrine 1.2

It's up to you to define their associations, purely because only you will know how you want your application to work. 定义它们的关联关系完全取决于您,纯粹是因为只有您才知道您希望应用程序如何工作。 Can a user have more than one group? 一个用户可以有多个群组吗? Only one? 只有一个? If a group is deleted, will all associated users be deleted? 如果删除了一个组,是否会删除所有关联的用户? These are the questions you need to ask yourself. 这些是您需要问自己的问题。

If you follow the example on Doctrine's documentation for Many-to-Many relationships (which coincidentally covers exactly what you need), you'll get there. 如果遵循Doctrine文档中关于多对多关系的示例 (巧合地恰好涵盖了您所需要的),您将到达那里。

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

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