views:

37

answers:

4

I was left a comment that many-many associations are to be avoided, but I cannot find the original comment/user who left me this info. So I'm asking the community, are many-many associations to be avoided, if so why, and what is the alternative?

example:

A restaurant offers many types of burgers which can be dressed with many different condiments.

Is this not a many-to-many association? Does it not require a relation table that contains the foriegn keys for the BURGER table and the CONDIMENT table?

Thanks in advance,

BW

+1  A: 

Yes, the relation between the burger and condiment is many-to-many. And yes, you will require a third table for linking these two tables.

Amr Hesham Abdel Majeed
+2  A: 

M:N associations cannot be avoided if one wants to model relationships like the burger/condiment one you mentioned. There is nothing intrinsically undesirable about M:N associations. And yes, they need a third table.

Often people try to put extra attributes on the relationship, incorrectly modeling two 1:N associations as an M:N one. Maybe this is what the OP meant about avoiding M:N associations.

binil
+1  A: 

This is not really a definite answer, but sometimes I find that I start off with a many-to-many relationship - for example, on a shopping website, orders to products. However, as I develop the application, I find that the link is more than just a link and is an entity in its own right that has it's own attributes and behaviours; in this case it would be called something like "line". So if I had thought through things like that properly in the first case, then I woudn't have made it many-to-many.

But of course, often that isn't the case.

Gnuffo1
+1  A: 

So I'm asking the community, are many-many associations to be avoided

Real world databases I'm working with do have many-to-many relations represented.

if so why, and what is the alternative?

Two one-to-many relations with a third table (aka the "join table"), which is anyway how you represent a many-to-many relation at the physical level.

Pascal Thivent