Remove on associated model without {load: false} throws an error
m1cr0man opened this issue · comments
Lucas Savva commented
As the title says. Here's my test code (generalized):
const patio = require('patio');
const db = patio.connect('mysql://lol:no@localhost:3306/my_db?minConnections=1&maxConnections=5');
const car = patio.addModel('cars').oneToMany('wheels');
const wheel = patio.addModel('wheels').manyToOne('cars').oneToMany('tyres');
const tyre = patio.addModel('tyres').manyToOne('wheels');
patio.syncModels().chain(_ => wheel.remove({id: 0}, {load: true}).chain(console.log), console.log);
And the error:
Error: Model error : null is not allowed for the wheelsId column on model tyres
at new patio.ModelError (/my/root/node_modules/patio/lib/errors.js:63:12)
at define.instance._typeCastValue (/my/root/node_modules/patio/lib/model.js:327:27)
at define.instance._setColumnValue (/my/root/node_modules/patio/lib/model.js:304:24)
at .job (/my/root/node_modules/patio/lib/model.js:784:22)
at .<anonymous> (/my/root/node_modules/patio/lib/model.js:219:33)
at Array.forEach (native)
at define.instance.__set (/my/root/node_modules/patio/lib/model.js:215:33)
at /my/root/node_modules/patio/lib/plugins/query.js:226:34
at .<anonymous> (/my/root/node_modules/patio/lib/model.js:698:37)
at resolveOrPromisfyFunction (/my/root/node_modules/patio/lib/utils.js:17:20)
I know it's not necessary to explicitly set load: true
, it's just so you can change it to false
quickly and see that the error goes away.