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 trialBen Os
20,008 PointsOne to one table relationships: I'm not sure I understand how it is best to make the link
Is it true to say for one-to-one relation ?
Say we have 2 tables that shares the same column (like "media_id") which is represented in a column of its own;
For example, say we have 2 media tables, each with 3 items. One deals with films and the other with T.V series. Besides them we also have an "media_id" tables that links them:
film id - 1,2,3 ... T.V series id - 1,2,3 ... id table: 1,2,3,4,5,6 (the 4,5,6 are actually the T.V series 1,2,3).
1 Answer
Simon Coates
28,694 Pointsboth table will typically have an id Field. But one table has another field that it the id of the other table. so given table A and B. A will have an id field. B will have an id field (or a primary key). But one (let's say B), will have a field called B.a_id (that has to contain an id contained in the other table). This covers one to one (provided you don't have multiple mappings) and one to many. Many to many requires use of a junction table (which just applies the one-to-many technique twice).