Learn to work with one-to-many associations in Rails. These are the most commonly used associations in a typical Rails project. Use these when one person or thing can have many related children records. Define the association in the model using “has_many” and “belongs_to” and then learn how to use association methods in the console.
- [Host] In the last movie,…we saw how to use one-to-one associations.…Now let's build on that…to understand how to work with one-to-many associations.…One-to-many associations are gonna be similar…to one-to-one associations,…but there are a few main differences that I wanna highlight.…First, one-to-many associations…are gonna be much more commonly used.…In a typical application, you'll rarely use one-to-one,…but you'll use one-to-many the most often.…Second, because we have one object related to many objects,…we're gonna use plural names.…That's both gonna be true when we define the association…and also when we call the methods on it.…
We'll see those in a moment.…And third, the relationship…is going to return an array of objects back to us…instead of a single object.…And that just makes sense, right?…If we're going to have many records associated with it,…we're going to have to store those in an array…so that it can hold all of those records.…You use a one-to-many association…when one object has many objects which belong to it,…
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.