Learn to implement a one-to-one association in Rails. You will use a one-to-one association when there is a unique item which a person or thing can have only one of, or when it is desirable to break up a large table of data for performance or organizational reasons. Define the association in the model using “has_one” and “belongs_to” and then learn how to use association methods in the console.
- [Instructor] In this movie…we'll learn how to implement…one-to-one associations in Rails.…Let's first consider…when you might actually use a one-to-one association…because there are two main use cases.…The most common reason is for unique items…that a person or a thing can have only one of.…For example, an employee has_one :office…or a student has_one :id_card.…The ID card is unique.…It belongs only to this one student…and to no one else.…And that student is only allowed to have one ID card.…It's certainly possible to imagine a scenario…where an employee might have two offices.…
But by using a has_one relationship,…we're rejecting that possibility in our design.…We've made it a statement of fact…that each employee can have only one.…At the point that we want to allow employees…to have more than one,…we would need to revise our relationships to match.…The second reason to use a one-to-one relationship…is to break up a single table.…For example, customer has_one :billing_address.…The columns associated with the billing address…
- 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.