Association
model "Author" {
}
model "Book" {
}
The Types of Associations
belongs_to
has_one
has_many
has_many through
has_one through
belongs_to
Association
model "Book" {
belongs_to "author" {}
}
add an optional database-level foreign key constraint
model "Book" {
belongs_to "author" {
foreign_key = true
}
}
has_one
Association
model "Supplier" {
has_one "account" {}
}
has_many
Association
model "Author" {
has_many "books" {}
}
has_many through
Association
model "Physician" {
has_many "appointments" {}
has_many "patients" {
through = "appointments"
}
}
model "Appointment" {
belongs_to "physician" {}
belongs_to "patient" {}
}
model "Patient" {
has_many "appointments" {}
has_many "physicians" {
through = "appointments"
}
}