Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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?

thanks!

1 Answer

Jay McGavren
STAFF
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.