Reputation: 66405
I'm a developer with limited experience of DB architecture. I just started to rough up what my DB for rethinkdb should look like and I came up with something like this:
User
Project
Language
Language Entry
It occurred to me that the IDs which join the data could go in a couple of different places:
What's best practice/more efficient?
My guess is that it's more efficient to do:
Especially where there could be a LOT of Language Entries across all projects, my assumption is that it would be slow to iterate through them all looking for matching Language IDs.
Upvotes: 0
Views: 41
Reputation: 52376
This isn't really a matter of efficiency, it falls under the discipline of logic and physical data modelling. The relational database should be created so that it can accommodate the real world situations (like a car manufacturer having multiple car models), but also be constrained so that it prevents any situations that cannot exist in the real world (like a car model having two manufacturers).
Here's some logic to follow, based on understanding the real-world situation.
language belongs_to project
and project has_many languages
language has_many projects
and project has_many languages
language has_many projects through project_languages
and project has_many languages through project_languages
I suspect that users and projects are in the third category, so you need the intermediate table, which could also store privileges.
With the correct associations, scopes etc. you'll then be able to do such magic as @user.projects
, @project.users
, @project.languages
, @user.project_languages - @user.languages
Upvotes: 1