Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem using registry plugin #39

Open
sapabg opened this issue Mar 7, 2018 · 0 comments
Open

Problem using registry plugin #39

sapabg opened this issue Mar 7, 2018 · 0 comments

Comments

@sapabg
Copy link

sapabg commented Mar 7, 2018

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
})
});
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant