Bookshelf: Cannot read property 'relatedData'

Created on 4 Dec 2015  Â·  3Comments  Â·  Source: bookshelf/bookshelf

Is there anyone that has had this problem before?

    {"msec":14.00135300308466,"error":"Cannot read property 'relatedData' of undefined","data":{"isBoom":true,"isServer":true,"data":null,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"},"headers":{}}}}

The stacklogs points towards lib\eager.js but I think it's something with my models. My models are the following:

USER

var Bookshelf = require('../');
var UserIndividual = require('./UserIndividual');
var UserCharity = require('./UserCharity');

var User = Bookshelf.Model.extend({
    tableName: 'user',
    userDetails: function () {
        //                   NAME           TARGET      TARGET
        return this.morphTo('userDetails', UserCharity, UserIndividual);
    }
});

module.exports = Bookshelf.model('User', User);

USERCHARITY

var Bookshelf = require('../');
var User = require('./User');

var UserCharity = Bookshelf.Model.extend({
    tableName: 'user_charity',
    user: function () {
        this.morphOne('User', 'userDetails');
    }
});

module.exports = Bookshelf.model('UserCharity', UserCharity);

Most helpful comment

Your relation functions need to return a value.
On Sat, 5 Dec 2015 at 09:42 xavier geerinck [email protected]
wrote:

Is there anyone that has had this problem before?

{"msec":14.00135300308466,"error":"Cannot read property 'relatedData' of undefined","data":{"isBoom":true,"isServer":true,"data":null,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"},"headers":{}}}}

The stacklogs points towards lib\eager.js but I think it's something with
my models. My models are the following:

USER

var Bookshelf = require('../');var UserIndividual = require('./UserIndividual');var UserCharity = require('./UserCharity');
var User = Bookshelf.Model.extend({
tableName: 'user',
userDetails: function () {
// NAME TARGET TARGET
return this.morphTo('userDetails', UserCharity, UserIndividual);
}
});
module.exports = Bookshelf.model('User', User);

USERCHARITY

var Bookshelf = require('../');var User = require('./User');
var UserCharity = Bookshelf.Model.extend({
tableName: 'user_charity',
user: function () {
this.morphOne('User', 'userDetails');
}
});
module.exports = Bookshelf.model('UserCharity', UserCharity);

—
Reply to this email directly or view it on GitHub
https://github.com/tgriesser/bookshelf/issues/1054.

All 3 comments

Your relation functions need to return a value.
On Sat, 5 Dec 2015 at 09:42 xavier geerinck [email protected]
wrote:

Is there anyone that has had this problem before?

{"msec":14.00135300308466,"error":"Cannot read property 'relatedData' of undefined","data":{"isBoom":true,"isServer":true,"data":null,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"},"headers":{}}}}

The stacklogs points towards lib\eager.js but I think it's something with
my models. My models are the following:

USER

var Bookshelf = require('../');var UserIndividual = require('./UserIndividual');var UserCharity = require('./UserCharity');
var User = Bookshelf.Model.extend({
tableName: 'user',
userDetails: function () {
// NAME TARGET TARGET
return this.morphTo('userDetails', UserCharity, UserIndividual);
}
});
module.exports = Bookshelf.model('User', User);

USERCHARITY

var Bookshelf = require('../');var User = require('./User');
var UserCharity = Bookshelf.Model.extend({
tableName: 'user_charity',
user: function () {
this.morphOne('User', 'userDetails');
}
});
module.exports = Bookshelf.model('UserCharity', UserCharity);

—
Reply to this email directly or view it on GitHub
https://github.com/tgriesser/bookshelf/issues/1054.

I can not believe I just looked over that return all the time ... Thanks! You literally saved my day haha!

This just totally saved me, can't believe I missed that as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jhnferraris picture jhnferraris  Â·  4Comments

Wtower picture Wtower  Â·  4Comments

1mike12 picture 1mike12  Â·  3Comments

leebenson picture leebenson  Â·  4Comments

Playrom picture Playrom  Â·  4Comments