Search code examples
hibernateormdatamodel

Are many-many relationships to be avoided and if so, what is the alternative?


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


Solution

  • 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.