Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.