Where can I read more about changes related to nested model parsing and submodels? This is something I had to implement just a week ago, and I resorted to overriding `set`. I wonder if they made it easier, or if there is a builtin support for nested models of some kind.
Jeremy, thanks! I tried overriding Model's `parse` in 1.0 but wasn't satisfied because it seems to be called in some cases but not the others. (I can't recall a specific example right now; maybe it was parsing the collection from server, or creating a collection using constructor).
Do you think there are drawbacks to overriding `set`? It seems to work well for me but I'd love to hear your opinion:
Comments
Where can I read more about changes related to nested model parsing and submodels? This is something I had to implement just a week ago, and I resorted to overriding `set`. I wonder if they made it easier, or if there is a builtin support for nested models of some kind.
Happy to oblige. There's no built-in convention for it, but you can do something like this:
... assuming that friends is an array of JSON objects suitable to be transformed into Person models.Jeremy, thanks! I tried overriding Model's `parse` in 1.0 but wasn't satisfied because it seems to be called in some cases but not the others. (I can't recall a specific example right now; maybe it was parsing the collection from server, or creating a collection using constructor).
Do you think there are drawbacks to overriding `set`? It seems to work well for me but I'd love to hear your opinion:
https://gist.github.com/gaearon/6689379
If you want something lightweight I'd go with the approach @jashkenas mentioned. But also might want to checkout:
https://github.com/PaulUithol/Backbone-relational