Reading your question again, I see my previous answer is about a different topic.
To answer your question: Say you have a table 'users' and a table 'groups', and table 'groups' has a foreign key 'user_id'. You've mapped these to the entities "User" and "Group" respectively. You can associate these 2 entities in 3 ways: 1) Bidirectional, meaning you have properties on both sides: Group::$user (ManyToOne, with "inversedBy") User::$groups (OneToMany, with "mappedBy") 2) Unidirectional, meaning you only have a property at the owning side: Group::$user (ManyToOne, without "inversedBy") 3) Unidirectional with join table: This last case is where we hit a problem with the setup so far. In order to _only_ have a property User::$groups, we need to map it as a OneToMany, but a OneToMany needs "mappedBy" which points to the owning side of the association. But we don't want the property Group::$user, so what to do? The only way you can solve this in Doctrine is to remove the foreign key 'user_id' from the table 'groups', and create a separate join table. How you do this you can read in the docs, but I hope this makes the situation clear :) PS: In my experience I never go with option 3 (unidirectional with join table), but with option 1 (bidirectional). It's easier to set up, and more efficient when it comes to db queries. -- Jasper N. Brouwer (@jaspernbrouwer) On 8 October 2014 at 12:37:07, Jasper N. Brouwer ([email protected]) wrote: > I've written some blog-posts about this subject: > > http://future500.nl/articles/2013/09/doctrine-2-how-to-handle-join-tables-with-extra-columns > > http://future500.nl/articles/2013/09/more-on-one-to-manymany-to-one-associations-in-doctrine-2 > > > -- > Jasper N. Brouwer > (@jaspernbrouwer) > > > On 8 October 2014 at 12:09:40, Javier Garcia ([email protected]) wrote: > > Hi, > > > > when should I use a One to Many, unidirectional with Join Table > > relationship? could you give me an example? > > > > http://docs.doctrine-project.org/en/latest/reference/association-mapping.html#one-to-many-unidirectional-with-join-table > > > > > > Thanks -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
