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

272
Vistas
Ensure that a referenced entry exists in db when we add its referencer (RxDB)

There is a database schema which includes two collections, customers and orders. Every order has a reference to its customer:

properties: {
  /* other properties */
  customer: {
    ref: 'customers',
    type: 'string'
  }  
}

The issue is when I try to save an order with a customer that does not exist in the database (for example, it can have been removed by that moment), this mischief would be silently managed:

const db = await createDB();
await db.customers.insert({
  name: 'John Doe'
});
await db.orders.insert({
  /* other properties */
  customer: 'Ann Lewis' // oops, there is no such a user in the db
}); // but no error would be thrown here
const order = await db.orders.findOne().exec();
const customer = await order.populate('customer'); // bare null here

So the populated customer is null even though it was marked as required with the schema.

How can I force an exisiting-checking rule for customer within a transaction?

about 4 years ago · Juan Pablo Isaza
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