Recall & Review
beginner
What is the main purpose of associations in Rails models?
Associations connect models to show how data relates, like linking a user to their posts. This helps Rails understand and manage related data easily.
Click to reveal answer
beginner
How does a
has_many association work in Rails?A
has_many association means one model owns many of another model, like a blog having many comments. It sets up methods to access those related records.Click to reveal answer
intermediate
Why do Rails associations improve code readability and maintenance?
Associations let you write simple code to get related data without complex queries. This makes code easier to read, understand, and change later.Click to reveal answer
intermediate
What role do foreign keys play in Rails associations?
Foreign keys link records in different tables. Rails uses them behind the scenes to connect models, like linking a comment to its post.
Click to reveal answer
intermediate
Explain the difference between
belongs_to and has_one associations.belongs_to means a model holds the foreign key and points to another model. has_one means a model owns one related model but the foreign key is in the other model.Click to reveal answer
What does a
belongs_to association indicate in Rails?✗ Incorrect
belongs_to means this model has a foreign key pointing to another model.Which association would you use if a user has many posts?
✗ Incorrect
A user owning many posts uses
has_many.Why are associations important in Rails models?
✗ Incorrect
Associations define relationships and make it easy to work with related data.
Where is the foreign key stored in a
belongs_to association?✗ Incorrect
The model with
belongs_to holds the foreign key.What does a
has_one association mean?✗ Incorrect
has_one means one-to-one ownership of another model.Explain in your own words why Rails uses associations to connect models.
Think about how people connect things in real life, like linking a book to its author.
You got /4 concepts.
Describe the difference between
belongs_to and has_many associations with examples.Consider who 'owns' the connection and where the key lives.
You got /4 concepts.