0

Here is my firebase data structure:

item:
    itemUID:
        Title: ""
        createdBy: userUID

media:
    mediaUID:
        Title: ""
        createdBy: userUID
        items:
            itemUID: true
            itemUID: true

user:
    userUID:
        firstname: ""
        lastname: ""

I would like the current user to edit one of their media lists. the media is basically a bunch of items and a title and who the media was created by, which is the current user. Other users can add the current user's items to their media and a reference to that item appears in "items" in the media. When the current user edits their media and wants to delete an item from the media, I would like to only delete the item if

  1. it was created by the current user
  2. it is not in anyone else's media

how would I go about doing this in swift? Thank you

Andrew Harris
  • 396
  • 7
  • 24

1 Answers1

0

In your current data structure it is very easy to find the list of media for a specific user. But it is quite hard to find the list of users for a specific media item. For your type of use-case you'll typically want to store the information in both directions: items per user, and users per item.

So I'd add two more top-level lists:

users_media
  $uid
    $mediaid1: true
    $mediaid2: true
media_users
  $mediaid
    $uid1: true
    $uid2: true

With these additional structures, your use-case becomes a bunch of reads of lists, and corresponding multi-location updates.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807