Question

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. How should i setup the relations in User or Group so that they are mapped through the user_group table?

I'm using Doctrine 1.2

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top