IT

Asociace v ORM

23.3.2016

Také si často rychle nevzpomenete, jakou asociaci pro daný případ použít?

Tady je stručný přehled:

Many to One

# Database schema:
#  albums             artists
#   :id           /--> :id
#   :artist_id --/     :name
#   :name

One to Many

# Database schema:
#  artists            albums
#   :id   <----\       :id
# :name       \----- :artist_id
#                      :name

Many to many

# Database schema:
#  albums
#   :id   <----\
#   :name       \     albums_artists
#                \---- :album_id
#  artists       /---- :artist_id
#   :id   <-----/
#   :name