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?