Saturday, April 15, 2017

How to create ManyToMany relation with extra foreign key in Doctrine 2

guys.

I have such entities: Company, User and Role.

User-to-Company relation is set with extra entity 'CompanyUser' because of extra columns that I need. So it's OneToMany(User-CompanyUser, Company-CompanyUser) and ManyToOne(CompanyUser-User, CompanyUser-Company).

The problem is that I need to set Roles for Users based on Company. For example, User can have many Roles in Company A and many roles in Company B. I see that like a table with columns user_id, company_id and role_id.

But I don't understand how should I set up this relation in User entity. Also to create an extra entity like CompanyUserRole?

Thanks!



via Shandur

Advertisement