I’m using realm flexible sync and I don’t know how to solve the following problem:
My app consists of the following domain architecture:
- a user can have many books
- a book can have multiple pages
- a page can have multiple paragraphs
The models would look like this:
class Book: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: UUID
@Persisted var name: String
@Persisted var pages = List<Page>()
@Persisted var ownerId = ""
}
class Page: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: UUID
@Persisted var label: String
@Persisted var paragraphs = List<Paragraph>()
}
class Paragraph: Object, ObjectKeyIdentifiable {
@Persisted(primaryKey: true) var _id: UUID
@Persisted var text: String
}
When opening the realm, I subscribe to each of those collections and have defined a role at the atlas backend so every user is allowed to read and write documents where the ownerId is identical to there userId.
No I’m wondering how to deal with the related collections. I think it’s not necessary to define the ownerId there as well, because they’re not accessed on their own and just accessible via their parent, at least in the UI. But I think that wouldn’t work considering the defined backend role because there’s no ownerId present.
Can someone help me out?