In sails.js I have the following models:
Site
module.exports = {
attributes: {
name: {
type: 'string',
required: true
},
active: {
type: 'boolean',
defaultTo: false
},
pages: {
collection: 'page',
via 'site'
}
}
};
Page
module.exports = {
attributes: {
name: {
type: 'string',
required: true
},
site: {
model: 'site',
required: true
},
modules: {
collection: 'module',
via 'page'
}
}
};
Module
module.exports = {
attributes: {
module: {
type: 'string',
required: true
},
page: {
model: 'page',
required: true
}
}
};
When I call GET /Site/1 I get the following:
{
"pages": [
{
"name": "First page",
"site": 1,
"createdAt": "2014-08-23T17:57:41.562Z",
"updatedAt": "2014-08-23T17:57:41.562Z",
"id": 1
}
],
"name": "First site",
"createdAt": "2014-08-23T17:56:57.143Z",
"updatedAt": "2014-08-23T17:56:57.143Z",
"id": 1
}
I'm using MongoDB and this would be dead easy to model as a nested document.. unfortunately I don't think Waterline supports that, hence the assocations/joins.
I can see that it's successfully outputting each page associated with a site, how do I make it so it also outputs the list of modules that are associated with each page?