Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!