Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
Realm, Accessing the Object property after deleting that Object

I am deleting a Realm db Object, but I want to access its value after deleting so that I can use it in other processings. This is how my code looks like:

const theObject = realm.objects('Products').filtered("_id == $0", "61bba17fc7e82eaae53527de")

//the fetched theObject(response) looks like this: 
[{_id:'61bba17fc7e82eaae53527de', name: 'Sugar'}]

var productName = theObject[0].name

realm.write(() => {

 realm.delete(theObject)

})

return productName //I want to use this productName here to do some other stuffs

I want to use/return the productName for doing some other things, but when i try to access it, i find it undefined or null.

I think this is caused because the theObject has been deleted and hence the productId can't be acceced, but I wonder why it is that way since i already caught that id initially when I assigned it before deleting. ie productName = theObject[0].name

Now,My question is, How can I still get/access/return that productName?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This shouldn't be possible. Comment out the delete, and console log productName to ensure things are behaving as you think they are.

Also it looks like your missing a var/let/const for productName

const productName = theObject[0].name

Edit:

Since these are async operations its possible that real.objects('Prodcuts') is losing the race to realm.delete(). You can solve this by awaiting your access request before attempting to deleting.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda