Reputation: 397
I am trying to fetch just a single object based on the primary key. I have already tried filtered and sliced it to 1 object. Still the object that i get is the first object from the collection.
Is there a way to only fetch the object if it matches the primary key? and return an error or empty collection if the key is not present.
On some research i did find a related topic around realm/swift. But not sure if React Native version has something built for it. An example will be great! Thanks!
https://github.com/realm/realm-cocoa/issues/1917
Upvotes: 2
Views: 2345
Reputation: 366
We just added a new method in v0.14.0 for this to Realm
instances: objectForPrimaryKey(type, key)
. If no such object exists, then it will return undefined
.
We're a little behind on getting the latest documentation online, but will get that up as soon as possible this week. You can read the API docs for this method in the repo here.
Upvotes: 2