Review
Topics Covered: Rails relations; validations;
Exercises
E1: Relation Review
- Why do we use relations? What are they good for?
- Will you ever write a relation on just one class, or will a relation always join two classes together?
- What types of relations did we learn about? What makes them unique? Can you give examples of each? Hint: We learned about 3 different kinds and an extension.
- What changes do you have to make to migrations and models for each relation?
E2: We Belong Together
What kind of relations would you use for each of the following models?
- Tweets and users
- Users and accounts
- Tweets and hash tags
- Stores and customers
- Shopping carts and items
- Shoppers and Carts
- Shopper and items in the cart that the shopper has
E3: Reddit on
Rebuild Reddit up to the end of exercises yesterday
from scratch. The reason we're starting from scratch on not our
d8
version is simple: repetition breeds memory. It may seem tedious, but please believe that 15 extra minutes now will save you
hours later.
This time, we're going to add relations and validations. BEFORE YOU START, think:
- What are the relationships between my models? You should have
User
, Story
, and maybe Category
- Do you need any join tables or
has_many through: ...
?
- What validations do I need? Are there constraints I want to put on my models?
- Each story must have a
title
, or user_id
, etc.