How do model different logical views on data
1
vote
1
answer
44
views
Simplified example of a data modeling problem that I have:
I have a domain model with an
image
table, a camera
table, a machine
table, a foreign key constraint between image and camera (taken_by_camera
), and a FK between camera and machine (installed_into_machine
).
image taken_by_camera camera
camera installed_into_machine machine
All of this is based on the data, we get from customers.
However, in our application we utilize the data almost always in terms of sets of images. So, we also have a set
table. Each image belongs to a set and for that we have a belongs_to_set
FK on the image
table.
image belongs_to_set set
My problem is that I would like to restrict the sets on containing images of a specific machine only, e.g.
set restricted_to_machine machine
With just these FKs in place, I have no constraint that ensures that all images that are connected via camera to a specific machine also end up being connected to the same machine via the set.
image_1 taken_by_camera camera_1
camera_1 installed_into_machine **machine_1**
image_1 belongs_to_set set_1
set_1 restricted_to_machine **machine_2**
How can I model something like this (logically but also in postgres).
PS: It should be possible to have images taken by different cameras in a set as long as these cameras are installed in the same machine.
Asked by Pete
(13 rep)
Jul 7, 2024, 10:20 AM
Last activity: Jul 7, 2024, 11:43 AM
Last activity: Jul 7, 2024, 11:43 AM