Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Remove on associated model without {load: false} throws an error #149

@m1cr0man

Description

@m1cr0man

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions