Frage

The tables are: contracts {id, user_id, unit_id} AND users {id}
A user can have several contracts, but EACH contract, can have only one user.

So, the question is: the many-to-many relates to the table itself (meaning: there are many contracts for many users, so it's many-to-many),
or to the record? (meaning: each contract can have only one user, so it's one-to-many)


edit:

Some clarification -

contracts

user_id      |     unit_id     |      id
- - - - - - - - - - - - - - - - - - - - - - - - - 
    455      |       455       |      1          
    455      |       115       |      1          
    344      |       225       |      1          
    222      |       455       |      1          

Please note, again: EACH user record can have many contracts, and EACH contract record can have one user, but in the table scope: they both can have many of the other.

War es hilfreich?

Lösung

One user to many contacts, in your own words.

"Many to many" means that there are one-to-many relationships both ways (a user can have many contacts and a contact can have many users) not just that there are many records in both tables. Many-to-many relationships involve a junction table in most RDBMs.

Andere Tipps

The relationship between users and contacts is one-to-many. That is, one user has many contacts.

This does not need an association table. You can just put the userid in the contacts table.

An example of a many-many relationship would be items and orders. Items be in many orders. Orders can have many items. In this case, you need an association table to properly represent the relationship in a relational database.

this seems to be one to many, one user can have many contacts

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top