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

Unique Key on two fields combined

Hi I am building an application in which I need to have combined Keys i.e.

table1 listings table2 facilities table3 listing_id, facilities_id (I want to create unique key combining both this fields so as to not have duplication.) how to do this ?

2 Answers

Well table3 would still have a primary key (the unique key for the table), then you would put validations on the other models (You are basically creating a join table).

My question, is it Listing has_many facilities? Or Listing has_one facility? What is the association between listing and facility?

Listing has many facilities. Listing can have standard default facilities and also custom added facilities