Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda