I have a list of organizations that contain users and locations.
Schema:
organizations (
organization_id
)
locations (
location_id,
organization_id
)
users (
user_id,
organization_id
)
user_locations (
user_id,
location_id
)
I have a table to contain which locations are assigned to which users.
My issue is that my user_locations
table can have a user with locations from any organizations. I want to create a constraint of some kind that will check that the location_id
assigned to the user_id
are within the same organization_id
.
Is this type of "grandparent" constraint/key possible without having to build triggers to check?