Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Many-to-many without intermediate table - is it possible?

I have two entities that usually have one-to-many relationship, but in rare cases should have an opportunity to be many-to-many. I don't want to join the tables with the intermediate table for every query - and i guess there are preferable patterns for "rare many-to-many", - (perhaps with additional table for m-t-m, with duplicate records or something). Any ideas?

UPD. Well, first of all i think about potential overhead with intermediate table (maybe i overestimate it), the second is about expressing real-world semantic that usually objects should have one-to-many relationship.

like image 884
rudnev Avatar asked Dec 13 '09 13:12

rudnev


1 Answers

A "rare many-to-many" relationship is still a M:M relationship, and should be modeled correctly. This involves creating an intermediate or association table linking the two tables together. Your queries will be slightly more complex but only involves an additional join. But you'll have the satisfaction and admiration of your peers that you modeled your tables correctly :)

Randy

like image 172
Randy Minder Avatar answered Oct 10 '22 23:10

Randy Minder