Reputation: 497
I am very new to Sails.js and I am trying to understand its magic.
I have three nested models using associations : Series.js -> Season.js -> and Episode.js.
Series.js
module.exports = {
attributes: {
/* other attributes */
seasons: {
collection: 'season',
via: 'series'
}
}
};
Season.js
module.exports = {
attributes: {
/* other attributes */
episodes: {
collection: 'episode',
via: 'season'
},
series: {
model: 'series'
}
}
};
Episode.js
module.exports = {
attributes: {
/* other attributes */
season: {
model: 'season'
}
}
};
Out of the box, I can get the seasons of a series using the route:
/series/:id/seasons
And also the episodes of a season using the route:
/seasons/:id/episodes
What I don't understand is why I can't get the episodes of a season of a series using this route:
series/:id/seasons/:id/episodes
Any idea why is this happening? I know I could use custom routes to get the behaviour I want, but it'd be nice to be able to do it without any further configuration.
I know Sails.js only allows one level population, but this doesn't seem the issue since I have set populate: false
.
Upvotes: 0
Views: 172
Reputation: 24958
Sails doesn't provide this route automatically:
series/:id/seasons/:id/episodes
because it doesn't really make sense if you think about it. If you already know the ID of the season, then the series it belongs to is irrelevant. Just use:
seasons/:id/episodes
to get the episodes you want.
Upvotes: 1