Hello community!
I’ve been working on a project where I have a realm model to keep track of every user’s last visit to a specific place-object. Here’s a simple description of my classes:
class Place: Object {
@Persisted(primaryKey: true) public var _id = UUID().uuidString
@Persisted public var ownerId: String
@Persisted public var lastVisits: List<LastVisit> = .init()
}
class LastVisit: Object {
@Persisted(primaryKey: true) public var _id = UUID().uuidString
@Persisted public var ownerId: String
@Persisted public var date = Date()
}
I set up two sync rules:
- For the Place Object: Everyone can read and write the Place-Object.
- For the LastVisit Object: Only the “owner” of a LastVisit can read and write his LastVisit Data.
The corresponding roles look like this:
"roles": [
{
"name": "Place",
"apply_when": {},
"document_filters": { "read": true, "write": true },
"read": true, "write": true, "insert": true, "delete": true, "search": true
},
{
"name": "LastVisit",
"apply_when": {},
"document_filters": { "read": { "owner_id": "%%user.id" }, "write": { "owner_id": "%%user.id" } },
"read": true, "write": true, "insert": true, "delete": true, "search": true
}
]
However, I’ve run into a rather puzzling issue:
I have a first client and user that adds a first LastVisit to the Place-Object.
When a second user reads the Place-Object, the lastVisit
list is empty, which is expected. But, when this client appends a new LastVisit Object to the List, it doesn’t append an object; instead, it overrides the whole List! This leaves me with one LastVisit-Object on the server-side collection, and the first client and user have an empty list.
What I would expect is that the server has all objects of all users stored and not that the Client overrides the whole List.
Is this flexible sync and list behavior a bug or intended? If anyone has any insights or has faced a similar issue, please let me know how you resolved it or if there are any workarounds.