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

Databases Querying Relational Databases Table Relationships One to Many Relationships

Leigh Maher
Leigh Maher
21,830 Points

Is it realistic for this relationship to be one-to-many?

I may be misunderstanding this but I'm just thinking that orders often contain more than one product, in which case an order can contain many products. But and order ID has to be unique so there would need to be a joining table that would take care of all of the lines on an order? The order_line table would contain: Order_ID, Product_ID, and maybe add some fields that could be unique to the order line, like size (assuming sizes are attributes and not unique product_ID's) or quantity?

2 Answers

Steven Parker
Steven Parker
229,744 Points

For the example shown in the video, the instructor defines this limit on the data: "...a Sale has 1 product...".

But your suggestion would fit a more typical real-world scenario; and then yes, an intermediate table to associate multiple products with each Sale would make sense.

Leigh Maher
Leigh Maher
21,830 Points

Thanks Steven. I understand now. I had thought that he was saying this as a matter of fact rather than setting limits on the relationship for the sake of making the example work. Would have been good to have seen a real world (realistic) example, as I still get confused by these relationships sometimes.