My app has a "Categories" model.
Categories can be children of other categories.
So there is a "CategoriesAssociations" model.
Here is the code :
/* api/models/Categories.js */
module.exports = {
attributes: {
name: {
type: "string"
},
parents: {
collection: "categoriesassociations",
via: "child"
},
children: {
collection: "categoriesassociations",
via: "parent"
}
}
}
/* api/models/CategoriesAssociations.js */
module.exports = {
attributes: {
parent: {
model: "categories"
},
child: {
model: "categories"
}
}
}
Now when I use the find
route aka /categories
I get this :
[
{
"createdAt": "2015-08-24T14:16:46.662Z",
"updatedAt": "2015-08-24T14:24:23.819Z",
"name": null,
"id": "55db274e424996cc7e7512e2"
},
{
"createdAt": "2015-08-24T14:18:29.748Z",
"updatedAt": "2015-08-24T14:18:41.105Z",
"name": "test",
"id": "55db27b5424996cc7e7512e4"
}
]
So no trace of the parents
and children
properties.
The associations are indeed created in the database for when I request /categories/55db27b5424996cc7e7512e4/children
I get this :
[
{
"parent": "55db27b5424996cc7e7512e4",
"child": "55db274e424996cc7e7512e2",
"createdAt": "2015-08-24T14:32:43.429Z",
"updatedAt": "2015-08-24T14:32:43.429Z",
"id": "55db2b0bc97cc73083017f60"
}
]
Sails docs states that the populate
configuration key for blueprints defines :
Whether the blueprint controllers should populate model fetches with data from other models which are linked by associations. If you have a lot of data in one-to-many associations, leaving this on may result in very heavy api calls.
The value is true
in my project but still, associations attributes don't get populated.
Did I misunderstand the docs or is there a problem with my project?
I use sails 0.11.x
The problem is I'm using sails-permissions which has overrides blueprints'
populate
config :I opened an issue to know why it's done globally and how to fix the problem.