Many-to-many (data model)

From Wikipedia, the free encyclopedia

In systems analysis, a many-to-many relationship refers to a relationship between two entities (see also Entity-Relationship Model) A and B in which A may contain a parent row for which there are many children in B and vice versa. Because most DBMSs only support one-to-many relationships, it is necessary to implement such relationships physically via a third junction table, say, AB with two one-to-many relationships A -> AB and B -> AB. In this case the logical primary key for AB is formed from the two foreign keys (i.e. copies of the primary keys of A and B). (For further reading see C J Date, "An Introduction to Database Theory").

In web application frameworks such as CakePHP and Ruby on Rails, a many-to-many relationship between database tables in a model is usually referred to as a hasAndBelongsToMany (HABTM) relationship.

[edit] See also