Active Record

Back End Lesson w/ Matt: Active Record Associations, Part 2


Lesson Objectives:
– Add a many-to-many relationship to an existing Rails app.
– Use a has_many :through relationship via the console.
– Build a list of associated objects on a show view.

From Lesson: We should be able to add Stars to the database, and associate those Stars with Movies... much like another popular website which shall remain nameless.

This sounds like a job for has_many :through.

In a many-to-many relationship, we must create a join table – a separate table that lists the ids of the two objects that we are joining together. –> I *think* this works like a new sheet in an excel file?

Appointment is known as a join model – it joins the Doctor model to the Patient model.

ERD – an entity relationship diagram. Engineers use these when designing databases to visualize the ways in which database objects will relate to one another.

NEVER EDIT SCHEMA DIRECTLY. Instead, edit the db->migrate->messed up file (in sublime) and then use:

bundle exec rake db:drop db:create db:migrate db:seed


– Step 9: references first added to movie_id instead of movie but once that was fixed with above step forgot / didn’t really know this is when to run rake db:seed THEN kept trying to find Hackers character Dade but first had to read Star of Jonny Lee Miller. Added him, found movie, added role to the Jonny star and now it we can move on! –> cool b/c all info cross accessible, movies, stars, specific roles. See by calling each model on a model:
* In most cases, as a junior developer, we won't need to know SQL but it would be good to learn on our own at some point, especially when working with bigger clients(?)

Rails Lesson w/ Mike: Model Methods:

Stubbing explained by Nicole: “for the sake of argument, let’s say this is the situation…”

what are your thoughts?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s