To keep Ember focussed and to minimize data transfer, I "cached" some attributes on some models. Example: Because I only need the name of an author, I cache it to the book:
In Rails: Book has_one :author In Ember: Book author_name: DS.attr("string")
So in Rails I compute the author_name and send it with the json data.
Now if I try to send data back to the server, I need to omit the cached attributes.
I tried overriding "serialize" in the Book model but that had no effect (which struck me as odd and illogical).
Eventually I've overridden the addAttribute in my adapter. So I now use:
adapter: DS.RESTAdapter.extend
serializer: DS.RESTSerializer.extend
addAttribute: (hash, key, value)->
cached_keys = [ "author_name", "more" ]
this._super(hash, key, value) unless cached_keys.contains(key)
But now the attributes aren't linked to "Book" anymore. Even more, I have more cached attributes on other models, but in here they are all mixed together. I can't imagine this is the best way to solve the problem. Any better ideas?
ember-data
. – mehulkar