Is this considered loop in my ERD?

736 views Asked by At

I have the following ERD diagram in which, each User has many Devices and takes many Photos. Each Photo is taken by one Device and each Device can take many Photos. Is this considered a loop in ERD context? If so, how can I avoid it?

ERD

1

There are 1 answers

0
Mike Purcell On BEST ANSWER

There are two ways to handle your sitch.

Option #1: Decouple user from device

user
    id

user_photo
    id
    user_id
    device_id

photo_device
    id
    token
    value

With this option when a user uploads a photo you can list out all devices from the photo_device table, then the user can select which device, and upon save, save user_id, and selected device_id into the user_photo table.

Option #2: Couple user to device

user
    id

user_photo
    id
    user_id
    user_device_id

user_device
    id
    user_id
    device_id

photo_device
    id
    token
    value

With this option, you can allow the user to associate commonly used devices to their account, so when they select which device they used when uploading the photo, the list goes from possibly hundreds to just a few. The only difference here is that we save the id of the user_device within the user_photo table vs just the photo_device id.