Good effort on this, you are thisclose! Here are my notes on your code:
-
When I go into the console and enter
User.newfor the first time, a newUseris 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: :throughThis is because you are chaining
through:statements on lines 10 and 12 of yourUsermodel. That is a no-no. And unnecessary. Your:throughonly 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:throughstatements. And heads up: per the above warning, Active Record is completely ignoring the second:throughon each line. It is like the second:throughdoesn't exist. Test what happens when you delete only the first:throughand 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:throughon each of these lines.) -
You don't need to specify the
foreign_keyon this line because Active Record is automatically going to look for apurchaser_idfield since you are associating it topurchaser. -
You do need to specify the
foreign_keyon this line because AR will be looking for asales_idfield, which does not exist. (You would need to specify:foreign_key => :shirt_id.)
Keep at it! Any questions, let me know.
-Phil