RealmObject returned by fin method of DynamicRealm has an exception on changes value

I have been working with the class RealmDynamic to find a document by collection name and primary key with the following code:

    final RealmObject? object =_realm.dynamic.find(id.collectionId, id.documentId);
`
this code returns a RealmObject as it is expected but, when I try to access to the value changes within object, there is an exception about inherence error.

Is there another way to search dynamically for a document by the collection name and its primary key ? 

Or why is this error occurring ?

What is the error that you’re seeing?

This is the error.

This is the way I am trying to access to the value changes

  RealmObject _retrieveDocument(Document id) {
    final RealmObject? object =
        _realm.dynamic.find(id.collectionId, id.documentId);

    if (object == null) {
      throw const ChassisException(message: 'Document can not be retrieved');
    }

    return object;
  }

    final Stream<RealmObjectChanges<RealmObjectBase>> stream =
        _retrieveDocument(id).changes;

this last piece of code returns this on changes value

Is there another way to search dynamically for a document by the collection name and its primary key ?

I see. Unfortunately, it’s not currently possible to use changes for a dynamically looked-up RealmObject. It’s not impossible to add support for it, but hasn’t been requested so far. Feel free to create an issue in GitHub - realm/realm-dart: Realm is a mobile database: a replacement for SQLite & ORMs. to make sure the team tracks it and other users are able to upvote/request support for it.

What about this question: Another way to search dynamically for a document by the collection name and its primary key ?
Is that possible with no specify the class type on a query?

No - that’s not possible, as the class is necessary to know what object types to construct. If you don’t specify the class, you’re going to get RealmObject instances, which still don’t have support for changes.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.