Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

How would you improve these db's and associations

Databases • Asked by Shaun Fahey

Database Structure

Hello people. I have my first proper paid Rails project to start soon, so I’ve been thinking about the database and the associations.

The two links below are the databases and the associations I’m thinking about.

http://thebackworksclinic.com/treatments.html

http://thebackworksclinic.com/jessica.html

This is what I’ve got in my README

Database Structure

1. User - Devise

  • name:string
  • bio:string
  • email:string
  • phone:integer
  • password:string

  • has_many :massage_treatments

  • has_many :massage_categorys

  • has_many :lava_treatments

  • has_many :lava_categorys

  • has_many :essential_treatments

  • has_many :essential_categorys

  • has_many :nail_treatments

  • has_many :nail_categorys

BODY MASSAGE TREATMENTS

2. MassageTreatment

  • user_id:integer
  • massage_category_id:integer
  • name:string
  • description:text
  • lenght:string
  • tagline:string
  • price:decimal{10,2}

  • belongs_to :user

  • belongs_to :massage_category

3. MassageCategory

  • user_id:integer
  • name:string

  • belongs_to :user

  • has_many :massage_treatments

LAVA SHELL TREATMENTS

4. LavaTreatment

  • user_id:integer
  • lava_category_id:integer
  • name:string
  • description:text
  • lenght:string
  • tagline:string
  • price:decimal{10,2}

  • belongs_to :user

  • belongs_to :lava_category

5. LavaCategory

  • user_id:integer
  • name:string

  • belongs_to :user

  • has_many :lava_treatments

6. EssentialTreatment

  • user_id:integer
  • essential_category_id:integer
  • name:string
  • price:decimal{10,2}

  • belongs_to :user

  • belongs_to :essential_category

7. EssentialCategory

  • user_id:integer
  • name:string

  • belongs_to :user

  • has_many :essential_treatments

8. NailTreatment

  • user_id:integer
  • nail_category_id:integer
  • name:string
  • description:text
  • lenght:string
  • tagline:string
  • price:decimal{10,2}

  • belongs_to :user

  • belongs_to :nail_category

9. NailCategory

  • user_id:integer
  • name:string

  • belongs_to :user

  • has_many :nail_treatments

Am I thinking about this correctly or not?

I can't help thinking I could simplify the categorys, because everything belongs to a category, but each category is completely separate as far as the treatments are concerned. If she wanted to add a category (offer a new service), that could be added to the category table from it's own controller/views, and then have a collection_select on the form, to pick a category when she adds a new treatment.

The more I think about it the more confused I get because i'm not sure how i'm going to pull the data out, I was thinking about a treatments dropdown menu on the navbar to pick Body Massages > Lava Shells > Essentials. But, how would that work if I had one category model and wanted to filter by category?

Also, If you look at the Essentials section on the site, that also has the two logical categories of Male and Female, the more I think about this the more I’m convinced that what I have above isn't the best way to do it, it would work but it just doesn't feel right.

Any suggestions would be great.
Regards, Shaun


Hey.

Use https://gist.github.com/ You can put all your code nicely in there and its easier to read plus others can edit (revisions) so you can see how it changed.

For db stuff with categories I find using tags easier sometimes. When the user can have multiple treatments you can add on multiple tags ( https://github.com/mbleigh/acts-as-taggable-on ). That way when you are viewing the user you would see all the tags (treatments) the user has or wants to get.

Another approach can be you have a treatments table. In that table you can have a list of all your treatments that the user can select via check boxes.

Also, this is a good read: http://guides.rubyonrails.org/association_basics.html I know when I started I just winged stuff until I started reading all the docs and guides to see how things work (I still don't know squat but I can still make an app based on docs, guides, stackoverflow, gorails, etc)

I'm sure Chris can chime in and probably give a better answer!


Hey @tabish

Category’s haven't been a problem for me in the past, I’ve done about a dozen prototype applications using them, the difference with this application is the amount of different category’s in the app. Like I said, I'm just scratching my head at the moment trying to think of a way to combine the four category’s into one, just not sure how to go about it yet.

I'm not using tags because there's not really any point, most tags would only find one thing, which you can already see when you selected the category you want.

When you say tables that's kinda what I’m after, each table/section/div on the main page would have one of the four category’s, and a different page to break each one down, but in each category the way I’ve done it above I’m always pulling from it from it's own category, instead of one main category model, i'm not sure if I could do that where everything is so different, for instance, a body wax isn't a massage :)


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.