rendrjs / rendr

Render your Backbone.js apps on the client and the server, using Node.js.
MIT License
4.09k stars 312 forks source link

[Doubt] Model options params are not set on model #470

Closed pjanuario closed 9 years ago

pjanuario commented 9 years ago

The collection sets this.params with options.params and this doesn't happen in models, I think would be good to have the same approach. I am not entirely sure how common would be.

https://github.com/rendrjs/rendr/blob/master/shared/base/collection.js#L38 https://github.com/rendrjs/rendr/blob/master/shared/base/model.js#L22

My use case is, our API have sub resources associated to a resource:

GET /venues => collection of venues
GET /venues/:id => specific venues
GET /venues/:venueId/musicGenres => music genres from a specific venue
POST /venues/:venueId/musicGenres => add a music genres to a specific venue
DEL /venues/:venueId/musicGenres/:id => music genres from a specific venue
GET /musicGenres => list of available music genres

So when I execute fetch on MusicGenres collection with a venue id, I would like the options.params of the model be the same as collection, this would allow to do:

venueMusicGenresCollection.remove(id).destroy();

So since, my model url is conditional to params on model, this would execute:

DEL /venues/:venueId/musicGenres/:id => music genres from a specific venue

At the moment I will be overriding model constructor to due this after executing default implementation, but maybe would be reasonable to do it on rendr model, or not. :)

pjanuario commented 9 years ago

Maybe it make sense for other uses cases but not for this one anymore, I figured that is going to out of scope. Sorry! :)