Been scratching my head on how to set this up and looking for your help. Trying to create an API and not 100% how my tables should relate to one another.

So lets say I have users, food, and food details. The user is able to post what he wants based on the food he selects. But they all should be able to be viewed in a single view if needed. not pizza only or pasta only. Each post should be able to stream together. pizza posts + pasta posts...

Here is what i am thinking below-

  • User Table: user_id, email, pass
  • Post Table: post_id, user_id
  • Pizza Table: post_id, peperoni, sausage, peppers
  • Pasta Table: post_id, sauce, cheese, onions

Would this way make sense? But then how would i know what pizza or pasta table to look into with just a post_id... This is the part i am a scratching my head over.

Thanks in advance.



api uri would be something like: /api/v1/posts

Example output for this would be a feed per post:

  • post_id 1 | Steve wants Pizza with Peperoni and Peppers @ 12:40
  • post_id 2 | Steve wants Pizza with Sausage and Peppers @ 12:35
  • post_id 3 | Kevin Wants Pizza with Peperoni, Sausage, and peppers @ 12:20
  • post_id 4 | Steve wants Pasta with Sauce and Cheese @ 12:15
  • It's a bit unclear what you're trying to do. What is the exact data that would be there and how would it be retrieved? What do you want to show as result? May 5, 2016 at 19:13
  • sorry about that - so a results set would be something like: post 1 - Steve wants Pizza with Peperoni and Sausage | Post 2 - Steve wants a Pizza with Peppers and Sausage | Post 3 - Kevin wants a Pizza with Peperoni and Sausage | Post 4 - Steve wants a Pasta with Cheese, onions, and sauce
    – Citti
    May 5, 2016 at 19:17
  • The API call would return all posts... but storing the data depending on if the user selects pizza or pasta they will have distinct options of what they could put on their food... does that make more sense?
    – Citti
    May 5, 2016 at 19:19
  • This is obviously abstract. The point i am trying to make is that each foods options are different and how do i store that in separate tables. but when i need to pull a list of all posts do that as well. another way you could look at this is cars. Chevy, Lexus, Audi, etc. Each car will have a unique set of options which would need to be stored in separate tables so that i am not stuck with a bunch of NULLs for options that Audi has that Chevy will never have...
    – Citti
    May 5, 2016 at 19:24
  • or could i keep all tables separate. and query them all once and order by timestamp? so basically no lookup table. Just Pizza posts, Pasta posts... and then when i need the full view of /posts i would just query all tables once and order by timestamp? not sure if that makes sense...
    – Citti
    May 5, 2016 at 19:38

1 Answer 1


Consider it this way. Products and possible options of products comprise system dictionary. Orders and specs are constraint by dictionary.

Pizza peperoni
Pizza sausage
Pasta cheese
Pasta onions
1 Steve Pizza 12:40
2 Steve Pizza 12:35
1 Peperoni
1 Peppers
2 Sausage 
2 Peppers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.