Jump to content

The ultimate community for Ruby on Rails developers.


Database with deep hierarchy and polymorphic relations

  • Please log in to reply
No replies to this topic

#1 malcoauri



  • Members
  • 2 posts

Posted 14 November 2013 - 06:09 PM

I'm developing some Rails application with geolocation features. There are many places for recreation: clubs, restaurants, pubs, etc. I need to store information about it in database. I've made "places" table with basic info about all objects (name, description, address, etc). Now I need to make tables for details about every type of place (club, restaurant, etc. I've got 2 questions.

1) Some places have similar information. For example, cafe and restaurant have average check and food type (Italian, Russian, etc) both. Should I put some basic info about places for eating in the same table (places table -> eating_places table -> cafes, restaurants, etc tables)?

2) Now there is table "place_types" for storing codes for types of places; "places" table have "type_id" field in order to allow to get, for example, all clubs - I need it because I use Rails to develop API for mobile client and admin panel to add new places. But after getting all places from "places" table I should get other details from specific tables ("clubs", "pubs", etc) - I can do it using "switch" operator; I've just read about polymorhic relations, should I use it? If yes, should I use "types" table or not?

Thanks in advance.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users