question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Realm returning proxy object when realm.objects is called

See original GitHub issue

I am using realm 2.1.1, react-native 0.51.0 and running debug code on Android emulator. Issue is that when I do let item = realm.objects('mySchema') proxy object is returned. Please note that I filter after. I can get array object by using itemArray = Array.from(item) but I have failed to update object within the write transaction. When I do so nothing happens

  realm.write(() => {
       itemArray[0] = newItem 
       //new item is object created using a class 
       //with the constrator. It works well in 
       //realm.create()
  });

Version of Realm and Tooling

  • Realm JS SDK Version: 2.1.1
  • Node or React Native: 6.11.4 or 0.51.0
  • Client OS & Version: Windows 10

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bdashcommented, Jan 15, 2018

filtered returns a collection of objects matching the given predicate. Your code snippets attempt to use that collection as though it’s a single object, which won’t work. You need to retrieve the relevant object from the collection in order to update it.

2reactions
itrevexcommented, Jan 15, 2018

Thanks for the response. It’s true I create the realm objects using Realm.create as specified in the docs. Say for example

//code sample_1
realm.write(() => {
  realm.create('Person', {
    name: 'Joe',
    // nested objects are created recursively
    car: {make: 'Honda', model: 'Accord', drive: 'awd'},
  });
});

Say I want to change the make of Joe’s car. I query the database to give me a Joe object as follows

//code sample_2 let Joe = realm.objects('Person').filtered('name= "Joe"');

And then I can update Joe’s car make by

//code sample_3
realm.write(() => {
  Joe.car.make= 'Isuzu';
});

My challenge is, code sample_2 returns a proxy object, and therefore I cannot run code sample_3 as it is given in that example.

One more thing you should note, is that this is the second project where I am using Realm db, with the first one everything worked as expected, as stipulated in the docs. The Realm version was 2.0.3.

This second one with Realm 2.1.1 has got me scratching my head. Any help will highly be appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RealmJS - Displays proxy object instead of list of objects
"Proxy" objects are the corner-stone of Realm and its zero-copy philosophy. All the Realm SDKs are implemented the same way - instead of...
Read more >
Object Models & Schemas - Java SDK — Realm - MongoDB
Realm guarantees that all objects in a realm conform to the schema for their object type and validates objects whenever they're created, modified,...
Read more >
The things I've learned using Realm | by Gabor Varadi - Medium
Anyone who's used Realm knows that there is a price to pay with proxy objects and lazy results, which also extends to Realm's...
Read more >
Lists - Beginning Realm on iOS - Introduction - YouTube
Each thread-local view returns proxy objects that only read from/write to the database when an accessor method is called, ...
Read more >
Realm Object Server Documentation
The Realm Object Server synchronizes Realms between devices, provides authentication and access control services for Realms, and offers “serverless” event ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found