Active Record Associations in Rails
Coming October 2017…
About this Course
Most of your Rails models are going to be connected to other models in some way. An Author has many Articles, and each Article belongs to an Author. A Doctor has many Patients, and a Patient may have many Doctors as well. Rails uses associations to make it easy to track these relationships in your database.
What you'll learn
- has_many :through
Active Record Associations
Our blog app doesn't allow users to tell us how awesome our posts are. This situation is, of course, unacceptable. So we're going to need a comments system. We need to be able to associate comments with a particular post.
Using Associations in Your App
Working with associated models in your controllers won't be much different from working with them in the Rails console. But rendering them in your views and representing the association in your routes might take a little more work. We'll cover those details and more in this stage.
More Association Options
When it comes down to it, associations really just make some changes to the SQL queries that Active Record runs on your database. If you want, Rails gives you the power to take more control over those queries. In this stage, we'll look at some options for doing that.
Resident Ruby and Go teacher for Treehouse. Author of Head First Ruby, a tutorial book on the core Ruby language.