epilogue
epilogue copied to clipboard
Include associated model that uses 'as' property
I have a model that contains two associates that link to the same model but as separated by using the 'as' property
classMethods: {
associate: function(models) {
// associations can be defined here
Device.belongsTo(models.Users, {as: 'createdBy'})
Device.belongsTo(models.Users, {as: 'updatedBy'})
}
Using the epilogue resource 'include' property I can happily include other associated models, but I am unable to work out how to include these two
var deviceResource = epilogue.resource({
model: models.Device,
include: [
{model: models.Network},
{model: models.DeviceType},
{model: models.Vendor},
{model: models.Software},
{
model: models.User,
as: 'createdBy', // this doesnt help
//primaryKeyField: 'createdById'
//attributes: ['firstName', 'lastName', 'username']
}
],
The error I get is
var primaryKey = i.model.primaryKeyField, ^
TypeError: Cannot read property 'primaryKeyField' of undefined at /Users/jamesas/Projects/Repositories/dokia.io/node_modules/epilogue/lib/Resource.js:126:31 at Array.forEach (native) at new Resource (/Users/jamesas/Projects/Repositories/dokia.io/node_modules/epilogue/lib/Resource.js:125:18) at Object.epilogue.resource (/Users/jamesas/Projects/Repositories/dokia.io/node_modules/epilogue/lib/index.js:62:20)
Anyone know how I can achieve this? My current work around is to write some milestone middle ware to insert the data i want
@semaja2 have you tried using auto association? Otherwise it might be useful to put together a simple test case that we can develop against.