Relationships between entities in a database may be one of the following:
- ⟷ one - to - one
- One element of A may only be linked to one element of B, and vice versa.
- Country and a capital city.
- ↤⇉ one - to - many
- One element of A may be linked to many elements of B, but a member of B is linked to only one element of A.
- One mother and multiple children.
- ⇇↦ many - to -one
- Same as previous, but sides are reversed.
- ⇇⇉ many - to - many
- One element A may contain a parent instance for which there are many children in B and vice versa
- A as Authors, and B as Books. An Author can write several Books, and a Book can be written by several Authors.
- This relationship requires additional
table that stores
’s of both A and B.
(↤⇉ one - to - many and ⇇↦ many - to - one are the same thing, but I like to see the “one” and the “many” sides clearly marked)
Prev: Configure a Database in Vapor
Next: Adding Indexes and Constraints to a Database in Vapor
Vapor 3 Tutorial Start
#pub #vapor #swift #db #ddl