Many-to-many (data model)
Encyclopedia
In systems analysis
Systems analysis
Systems analysis is the study of sets of interacting entities, including computer systems analysis. This field is closely related to requirements analysis or operations research...

, a many-to-many relationship is a type of cardinality
Cardinality (data modeling)
In data modeling, the cardinality of one data table with respect to another data table is a critical aspect of database design. Relationships between data tables define cardinality when explaining how each table links to another....

 that refers to the relationship between two entities (see also Entity-Relationship Model
Entity-relationship model
In software engineering, an entity-relationship model is an abstract and conceptual representation of data. Entity-relationship modeling is a database modeling method, used to produce a type of conceptual schema or semantic data model of a system, often a relational database, and its requirements...

) A and B in which A may contain a parent row for which there are many children in B and vice versa. For instance, think of A as Authors, and B as Books. An Author can write several Books, and a Book can be written by several Authors. Because most database management systems only support one-to-many
One-to-many
One-to-many may refer to:* Multivalued function, a one-to-many function in mathematics* Fat link, a one-to-many link in hypertext* Point-to-multipoint communication, communication which has a one-to-many relation-See also:*One-to-one...

 relationships, it is necessary to implement such relationships physically via a third junction table (cross-reference table)
Junction table
In database management systems following the relational model, a junction table is a table that contains common fields from two or more tables. It is on the many side of a one-to-many relationship with each of the other tables...

, say, AB with two one-to-many
One-to-many
One-to-many may refer to:* Multivalued function, a one-to-many function in mathematics* Fat link, a one-to-many link in hypertext* Point-to-multipoint communication, communication which has a one-to-many relation-See also:*One-to-one...

 relationships A -> AB and B -> AB. In this case the logical primary key for AB is formed from the two foreign key
Foreign key
In the context of relational databases, a foreign key is a referential constraint between two tables.A foreign key is a field in a relational table that matches a candidate key of another table...

s (i.e. copies of the primary keys of A and B).

In web application framework
Web application framework
A web application framework is a software framework that is designed to support the development of dynamic websites, web applications and web services. The framework aims to alleviate the overhead associated with common activities performed in Web development...

s such as CakePHP
CakePHP
CakePHP is an open source web application framework for producing web applications. It is written in PHP, modeled after the concepts of Ruby on Rails, and distributed under the MIT License.-History:...

 and Ruby on Rails
Ruby on Rails
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.-History:...

, a many-to-many relationship between database tables in a model is sometimes referred to as a HasAndBelongsToMany (HABTM) relationship.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK