ruby on rails - Database design for categorized to-do app -


i'm trying figure out best (most logical) way of designing database app allow user crud to-do tasks (more or less), however, they're organized hard-coded categories.

so let's you're go favorite department store. need hit women's floor , pick girlfriend shoes ordered, , matching dress (which on other side of store, on same floor.) then, need go boy's department little brother, , pick 2 different pairs of shorts, 1 pair of pants, , new pair of shoes.

the women's floor , boy's department 2 examples of categories shopping list items fall into.

so looks this:

* women's floor      1 pair shoes      1 dress  * boy's department      2 shorts      1 pant      1 pair shoes 

so database design so...

categories: id, title listindex: id, user_id shoppinglist: id, listindex_id, category_id, item_id, order, active items: id, name, category_id 

categories boy's department, women's floor, etc. users not able create new categories, instead, predefine categories

listindex provide master relation shopping list whole.

shoppinglist actual shopping list (active 0/1, user have way remind bought item / put in cart.)

items have list of items available put to-do tasks. categorize these ourselves on back-end.

is right way of doing it?

hopefully understood description of problem correctly thinking here's 1 way lay database , models out. don't think need listindex:

database tables

categories: id, title  shoppinglists: id, user_id, order, active  items: id, title  shoppinglistitems: id, item_id, shopping_list_id, quantity  categorizeditems: id, category_id, item_id  users: id, name 

models

user: has_many shopping_lists  shoppinglist: belongs_to user has_many shopping_list_items has_many items, through shopping_list_items  items: has_many categorized_items has_many categories, through categorized_items (optional: query item shopping lists on) has_many shopping_list_items has_many shopping_lists, through shopping_list_items  categories: has_many categorized_items has_many items, through categorized_items 

my thinking --

individual categories static, that's pretty straight forward.
shopping lists represent user's (via user_id) list of items purchased. link between item , shopping list take place in join table called shoppinglistitems each row links relationship between list, item, , quantity.

items interesting because in example item can in multiple categories. i.e. "pants" can in boys/girls/men/women , pets :(. support think can use join table called categorizeditems lets query "items in particular category" or "categories item in".


Comments

Popular posts from this blog

Java sticky instances of class com.mysql.jdbc.Field aggregating -