Ruby Active Record Associations in Rails Active Record Associations Has Many Through Associations

Eylon Cohen
Eylon Cohen
4,779 Points

connecting two models with a has_many_through instnacer while updating

In the example you gave, you had to create a has_many_through model's instance with a reference to a model 1 instance, and other information (step 1) and then append it to a mode 2 instance (step 2). or - create the referance directly naming a model 1 instance and a model 2 instance (step 1), and then updating the required information of the has_many_through models' instance (step 2). in the example - create a subscription to a magazine of x monthes and then append it a subscriber OR connect a subscriber to a mazine and then update the monthes created subscription.

Is there a way to do that in one step?


1 Answer

Jay McGavren
Jay McGavren
Treehouse Teacher

Not sure I understand the question. There's no Rails generator that will write the code for the associations for you, if that's what you mean. The technique shown in the teacher's notes is about the fewest number of steps you can take.