Active Record Associations

Topics 

  • What is an Association? 
  • Auto-generated methods 
  • How to implement Association? 
  • Cardinality 
  • Eager loading Association

What is and Why Use Associations?

What is an Association? 

  • Represent relationship between database tables, whose relationship is constructed through foreign keys or join table 
    • Examples: "A Customer has many Order's" or "An Order belongs to a Customer". 
  • Cardinality relationship 
    • One-to-one: A person has a single primary address 
    • One-to-many: A school has many students 
    • Many-to-many: A course has many students and each student take many courses

You must have an active subscription to download PDF and Lab Zip of this course topic.Please click the "Subscribe" button or the "Login" button if you already have an account.