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

Pedro Henrique Knoll Giacometo
Pedro Henrique Knoll Giacometo
6,669 Points

Database Modeling

Hello,

I'm using the treehouse courses to build a review site application.

I have an User model and a Venue Model. Both of them has one address. Is it the case to use a polymorphic association?

The diference between the addresses models are the latitude and longitude columns (necessary at the Venue model and not necessary for the User model). In this case what is the best approach?

3 Answers

Todd Hayes
Todd Hayes
1,513 Points

What do both models look like?

Pedro Henrique Knoll Giacometo
Pedro Henrique Knoll Giacometo
6,669 Points

Todd,

The User table has the columns:

Id First Name Surname Email Phone

The Venue table: Id Name Description Category_id Phone

The Address table
State City Street Number Zip Code Longitude Latitude

  • The latitude and longitude columns are not necessary to the User model. So, i don't know how the best association between the tables. Is it a good practice two tables to represent the same data (one table for User address and other to Venue address)?
Todd Hayes
Todd Hayes
1,513 Points

It isn't good practice to repeat the same data over multiple tables. You should normalize your data so that you don't have repeat data, but that data properly represents the right object or thing.

So, for your user, the address represents the VENUE where they are, as opposed to placing the address in the User table, which would represent the user's address, not the Venue address.

Your table setup, as it is now, would make it so the Users or Venue table would need a foreign key to represent the Address from the Address table in order for a User or Venue to use the Address table to represent the User's or Venue's address.

And make sure the Address has an ID of some type as a primary key, even if it's a lookup table.