seegno / bookshelf-cascade-delete

Cascade delete with Bookshelf.js

Home Page:http://seegno.github.io/bookshelf-cascade-delete

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem using registry plugin

sapabg opened this issue · comments

Ho there, I am using bookshelf with registry plugin and I have the following model:
var bookshelf = require('../bin/database');
var cascadeDelete = require('bookshelf-cascade-delete');

bookshelf.plugin(cascadeDelete);
bookshelf.plugin('registry');

var Client = bookshelf.Model.extend({
tableName: 'clients',
hasTimestamps: true,

users: function() {
    return this.hasMany('User');
},

companies: function() {
    return this.hasMany('ClientsCompany');
},

jobs: function() {
    return this.hasMany('ClientsJob');
},

candidates: function() {
    return this.hasMany('Lead');
}

}, {
dependents: ['users' ]
});
module.exports = bookshelf.model('Client', Client);

I am trying to use cascade-delete but it gives me an error:
TypeError: Cannot read property 'column' of undefined
at Child.cascadeDelete (C:\Projects\copy\frozen-crawl\node_modules\bookshelf-cascade-delete\dist\index.js:95:54)

I guess it doesn't like the string in hasMany(). I have a ton of models using the registry plugin and I'll appreciate a way to make this work without having to modify all of them...
Thanks in advance...
EDIT: here is the route:
router.delete('/:id', function(req, res, next) {
Client
.forge({ id: req.body.id })
.destroy()
.then((deleted) => {
res.status(201).json({
message: 'Client deleted'
})
})
.catch(err => {
console.log(err);
res.status(500).json({
title: 'An error has occured',
error: err
})
});
})