type Chat @model {
id: ID!
name: String!
messages: [Message] @hasMany(indexName: "byChatID", fields: ["id"])
}
type Message @model {
id: ID!
content: String!
role: MessageRole!
chatID: ID! @index(name: "byChatID")
chat: Chat @belongsTo(fields: ["chatID"])
}```
Here is a minimal schema example.
The idea is that we observe incoming messages in a chat.
When I run this setup the initial snapshot gets the existing messages, but after a new message is saved/created, a new snapshot is never emitted.
``` final sub = Amplify.DataStore.observeQuery(
Message.classType,
where: Message.CHAT.eq(chat.id),
).listen((snapshot) …```
If I remove the predicate entirely, observing
“all” messages, also from different chats, then I do get subsequent snapshots on each save.
Is this intentional when using relation predicates? Or if it’s supposed to work: what am I missing?
#Amplify Flutter (Gen1) – observeQuery doesn’t emit updates with relation predicate (@belongsTo)
4 messages · Page 1 of 1 (latest)
Hi @stiff hollow, thank you for bringing this up, we have seen a similar issue where updates are not being propagated when query predicates are used on setup of Datastore. I will investigate this one in step with that issue that is already being worked on, I believe they are related. Can you tell me what platform you saw this issue on? Does it occur on both iOS and Android?
@strong stream thanks for your message. Yes this happens on both. Tested it in both simulators and also on a physical iOS device.
Just as a side note, because I saw it multiple times now. The initial snapshot is sometimes not complete. (12 items in DB but only 8 retrieved, even though a DataStore full sync went through)
By the way, in the meantime as a workaround you may be able to call Datastore.start and then Datastore.start one after the other when you need to sync, restarting datastor should force a remote sync