Need help with Bookshelf.js polymorphic relations
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?