Alternately, you can override can.Model.models/can.Model.model to do preprocessing on all data that comes back through the declarative layer (i.e. for findAll, findOne, create, and update):
- findAll : "GET /things"
- , models : function(rawlist) {
- // Do whatever on the list
- return this._super(rawlist); // this mostly just calls model() on each element to make an instance, but in a very
- // type-safe and efficent way around the source list.
- }
- , model: function(rawthing) {
- // Do whatever to each rawthing
- return this._super(rawthing); // to modelize the raw object
- }
Advantage of doing it this way is that you can make changes in superclasses that are respected and added to in subclasses. Disadvantage is that you can't distinguish whether the raw lists/objects came through findAll, findOne, update, or create.