开发者

Doctrine 2/DB design question: Users, Companies, UsersCompanies Reference Table, and where to include field for current company?

开发者 https://www.devze.com 2023-03-15 15:34 出处:网络
I\'m using Doctrine 2 for my ORM and for my app I have Users, who can h开发者_运维技巧ave a many to many relationship with Companies, but a user can only have one active/current company.My question is

I'm using Doctrine 2 for my ORM and for my app I have Users, who can h开发者_运维技巧ave a many to many relationship with Companies, but a user can only have one active/current company. My question is where to include the field marking the user's current firm. My thoughts are that there are two options: 1) Adding an isCurrent field to the UsersCompanies reference table. However, if I want to get a user's current company, I would have to cycle through the a user's UsersCompanies references and check the is_current field for each reference. 2) Putting a current_users_companies_id in the user's table, so that it can be easily accessed.

As always, I appreciate your time and input.


Well, since the user can have only one current company, it would lead me to think it's a specific one-to-many relationship. Thus the best (and the simplest :) ) way to do it would be to just have the current_company_id property in your user object.

0

精彩评论

暂无评论...
验证码 换一张
取 消