Skip to content

Problem using registry plugin #39

@sapabg

Description

@sapabg

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

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