Is there a way to tell Sequelize that I would like to get the nested behavior of "belongsTo" in the output of a raw query result?
In my example I have a simple findAll query that includes the Attribute table: Item.findAll({include: models.Attribute}). Giving this result:
[
{
"Id": 1,
"AttributeId": 1,
"Value": "(IA) FIRST VALUE",
"createdAt": "2015-10-30T22:40:00.603Z",
"updatedAt": "2015-10-30T22:40:00.603Z",
"Attribute": {
"Id": 1,
"Definition": "{\"A\": true, \"B\": false}",
"backward": 4,
"forward": null,
"createdAt": "2015-10-30 22:39:59.883 +00:00",
"updatedAt": "2015-10-30 22:40:00.179 +00:00"
}
}
]
I have a raw query that will return Items and I would like their Attribute model filled. Is there a way to coxe Seqelize into giving the same nested behavior in a raw query given this example?
models.sequelize.query("....", {type: models.sequelize.QueryTypes.SELECT, model: models.Item, include: models.Attribute})
[
{
"Id": 1,
"AttributeId": 1,
"Value": "(IA) FIRST VALUE",
"createdAt": "2015-10-30T22:40:00.603Z",
"updatedAt": "2015-10-30T22:40:00.603Z"
--- MISSING ATTRIBUTE MODEL ---
}
]
I suspect its a matter of joining in the correct information and naming it correctly?