Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philsof/419ec80dbc06df9ec26a to your computer and use it in GitHub Desktop.
Save philsof/419ec80dbc06df9ec26a to your computer and use it in GitHub Desktop.
Code review: pair-edwardgemson,mirascarvalone branch for active-record-associations-drill-shirts-challenge

Good effort on this, you are thisclose! Here are my notes on your code:

  • When I go into the console and enter User.new for the first time, a new User is instantiated, but I also get this warning message: /Users/Phil/.../active-record-associations-drill-shirts-challenge/app/models/user.rb:10: warning: duplicated key at line 10 ignored: :through

    /Users/Phil/.../active-record-associations-drill-shirts-challenge/app/models/user.rb:12: warning: duplicated key at line 12 ignored: :through

    This is because you are chaining through: statements on lines 10 and 12 of your User model. That is a no-no. And unnecessary. Your :through only needs to get to a table that already has an association to the table you are trying to reach. That's why you don't need two :through statements. And heads up: per the above warning, Active Record is completely ignoring the second :through on each line. It is like the second :through doesn't exist. Test what happens when you delete only the first :through and then what happens when you delete only the second :through. Both ways should work. I believe the best practice is to associate with the table closest to the table you are ultimately trying to reach. (Thus, you would delete the first :through on each of these lines.)

  • You don't need to specify the foreign_key on this line because Active Record is automatically going to look for a purchaser_id field since you are associating it to purchaser.

  • You do need to specify the foreign_key on this line because AR will be looking for a sales_id field, which does not exist. (You would need to specify :foreign_key => :shirt_id.)

Keep at it! Any questions, let me know.

-Phil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment