I m working on a simple Rails app called lists4me to create a minimalistic task management application and learn Rails in the bargain. The tables I ve setup are users, categories, projects, tasks and steps. Basically a user has many categories, a category has many projects, a project has many tasks and a task has many (actionable) steps. Currently the user_id field is set in the categories table but not in the rest of the tables.
Recently I was looking at the data that is posted form todoist.com when new tasks or projects are created, the user_id seems to be sent as well. Since I ve set a user_id only on the categories table, this got me thinking should all of my tables have a user_id as a field as well? If so then why?
Basically, to answer that, I would consider the question of “Will I ever need to know to which user a (project | task | step) belongs to?”
If that will never be an issue, either because it won’t be necessary or because you can simply work by joining Users to (Projects | Tasks | Steps) via Categories, then you’ll be OK without having a user id field in the other tables.
If, however, you’re going to frequently want to look up say, all outstanding tasks for a given user, it would probably be worth it to add a user id field there, to save the join operations, which if my understanding is correct, are not terribly fast.