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

One-To-Many Relationships using Ruby

Hi Everyone,

I'm new to Ruby, and had a simple question.

I have two tables: one called Businesses, and the other called Events. I need to make a third table called Business_Events, where this third table is a one-to-many relationship with Businesses and Events.

One Business can have many Events, but all Events are not necessarily hosted by Businesses.

I made a model for Businesses, Events, and Business_Events. Would I just need to do a has_many within my Business_Events model which refers to the tables of Businesses and Events?

1 Answer

Hi Abhishek -

If you haven't already, I recommend you review the documentation for ActiveRecord associations at http://guides.rubyonrails.org/association_basics.html

It's good documentation of associations, and details the different types of relationships or associations between models. The examples included are very informative.

Hopefully the documentation will guide you in creating the appropriate associations between your models.

Best of luck!

Ronald