I have a Business model in my application, which will be storing information about
- Restaurants
- Bars
- Stores
- Hair Salons
- Etc
Some of the businesses share attributes/amenities:
- Wifi
- A/C
- Accesibility
- Etc..
But some are specific for a single type of businesses, for example restaurants:
- Take out
- Delivery
- Dress code
- Outdoor seating
I am wondering what would be the best way of modelling this information in the DB?
My current thinking:
Use a single table for Business that will hold all the information and attributes. Most of the attributes are boolean, therefore whenever an attribute does not apply to a business type, it will simply be false.
I am not sure however, if there is a better way of doing this. Also not sure about how to handle these differences at the view level. For example, when creating a business, I want the option the display/set those attributes that are applicable to the business type.
That is the way I would do it. You should have an attribute called
business_typethat lets you choose what attributes to display.For example in the show view:
You could use jQuery to change what fields are available on the new form based on what restaurant type it is:
If you want to avoid having a bunch of database columns, you could use the key-value store in rails 3.2 (3/4 of the way down this page):
Make a column called
amenities. Then inbusiness.rb: