I have two entities that describe a Project and an Item (product). When an item is added to a project, I create a relationship entity ProjectItem.
Separate from that I have a Space entity (like a room) and a relationship between a Project and Space as in ProjectSpace.
In my application there is a flow that describes assigning a specific quantity of an item to a space, e.g. adding 10 chairs to a room. Here is where I'm not sure how to design this association table.
The front-end can simply request that an item_id
, project_id
and space_id
be associated with a quantity of 10. The back-end can check that there is a relationship record project_item
(for project_id
and item_id
) and a valid project_space
record (for project_id
and space_id
) to validate the entry.
Now I wonder whether my Assignments table should be constructed as a relationship between:
project_item_id
withproject_space_id
withquantity
project_id
withitem_id
withspace_id
withquantity
project_item_id
withspace_id
withquantity
The question is about flattening relationships vs nesting relationships in a table design.
EDIT The flow goes like this:
- An item gets selected for a project (like adding it to a pool of items for this project), hence
project_item
- Spaces have already been associated with projects, hence
project_space
- Only items that have been added to a project can be added to spaces, and only to spaces that belong to the same project