Ember.js - Not sure how to model data -
i'm using restadapter ember data work json payload. part of payload contains data such
"links": { "facebook": "http://www.facebook.com/dailypuppy", "twitter": "http://twitter.com/dailypuppy", "officialwebsite": "http://www.dailypuppy.com/" },
i'm not sure how model data. noticed restserializer has normalizepayload
function, figured i'd give shot instead of restadapter. used so
normalizepayload: function(payload) { payload.facebookurl = payload.links.facebook; payload.twitterurl = payload.links.twitter; payload.myspaceurl = payload.links.myspace; payload.officialwebsiteurl = payload.links.officialwebsite; delete payload.links; return payload; }
problem approach restserializer doesn't support findquery
method, rely on. error saying tried load query adapter not implement findquery
any on appreciated.
from you're describing, think, mis-use serializer (read: in place of an) adapter. won't work. don't this. kinds of evil befall you.
you describe part of payload, assume part of json data object conforms in every other aspect expectations of restadapter , restserializer.
now, overwriting normalizepayload shown should work, but don't use restserializer instead of restadapter. replace serializer inside restadapter. if (using ember-cli
) generate application adapter (ember g adapter application
) can customize serializer restadapter (app/adapters/application.js
):
import ds 'ember-data'; export default ds.restadapter.extend({ serializer: ds.restserializer.create({ normalizepayload: function(payload) { function donormalize(payload) { payload.facebookurl = payload.links.facebook; payload.twitterurl = payload.links.twitter; payload.myspaceurl = payload.links.myspace; payload.officialwebsiteurl = payload.links.officialwebsite; delete payload.links; return payload; } // change 'attractions' other payloads here if(array.isarray(payload.attractions)) { payload.attractions = payload.attractions.map(donormalize); return payload; } else { return donormalize(payload); } } }) });
(code untested, should show idea)
since, probably, not payload contains links
property, may want customize adapter special thing
- replace application
thing
in i've written above, , you've got specialized thing
adapter. isn't thing
continue use default application adapter.