Module 07 Β· ActiveRecord β Lesson 3 of 5 Β· ~15 min
Associations
Booking connects Walker and Dog
A dog walk needs three things to exist: a Walker doing the walking, a Dog going on it, and the booking details themselves. Generate Booking with two references columns β Rails' shorthand for "this points at another table":
bin/rails g model Booking walker:references dog:references starts_at:datetime duration_min:integer price_cents:integer status:string
references does two things at once: it adds a walker_id/dog_id foreign-key column (with a real foreign-key CONSTRAINT in the database, not just a plain integer), and it writes belongs_to :walker / belongs_to :dog into the generated model automatically β you get that part for free.