I have a model AccessToken which belongs to multiple models using the keyable_id and keyable_type property.
I need to access access_tokens using the associated accounts.
Here is what my AccessToken model looks like:
module.exports = baseModel =>
baseModel.extend({
tableName: 'access_tokens',
keyable() {
return this.morphTo('keyable', 'Account', 'Project', 'User');
}
});
Here is what my Accounts model looks like:
module.exports = baseModel =>
baseModel.extend({
tableName: 'accounts',
accessTokens() {
return this.morphMany('AccessToken', 'keyable');
}
});
But all I get is an empty array for access_tokens. Does anyone know how to go about to solve this?
Stian Bakken
Full stack development with NodeJS/Aurelia
From the docs it looks like you have to import the actual model, and not refer to it by string.
Try something like this?
var Account = require('./account.js'); var Project = require('./project.js'); var User = require('./user.js'); module.exports = baseModel => baseModel.extend({ tableName: 'access_tokens', keyable() { return this.morphTo('keyable', Account, Project, User); } });