When trying out the newest version of Ember data it seems that relations should now be represented as models: ["1", "2", "3"] instead of model_ids: ["1", "2", "3"]. I’ve monkey-patched ActiveModelSerializer to fit with this new style.
When the records are saved back to the server, obviously I get the records without the _ids which conflicts with what ActiveRecord is expecting. So I was ready to write a special deserializer for my Rails controllers.
However, I read this old AMS pull request and I saw that the jj-abrams website documentation still uses the model_ids style (maybe because they just haven’t been updated yet).
Does anyone have some insight into the direction of this API in the near-future? I’m wondering if Ember Data will be sticking with the current relationship serialization style, heading for something more like jsonapi.org with the nested links styax, or going back to the current ASM style with _id and _ids. Also does anyone have this worked out with ASM, Rails, and the new Ember Data in a way they like?
It says you can also specify a different root for the embedded objects than the key used to reference them and though their example is about embedded the whole associated objects rather than their id but it might work.
class PostSerializer < ActiveModel::Serializer
embed :ids, include: true
attributes :id, :title, :body
has_many :comments, key: :comment_ids, root: :comment_objects
end
I’ve been reading all that info on ASM and looking over the recent issues on Ember Data. It seems like both ASM and Ember Data have a soft commitment to eventually support the JSON API spec… at some point. I’m currently weighing my options of either getting Ember Data to use the _ids style again or trying to get a JSON API style going on both ends.
I’ve been trying to adjust my API so that it uses “links” because the number of records I was getting to was causing 414 errors (request URL too large or 404 because of malformed request - chopped off bits of id specifiers).
Only trouble is, it seems to be missing data when I do it this way. I was wondering if that’s coz I’m specifying the links incorrectly in my serializer.
Seems that if I take off the links from my serializer, things start sort of working again… but I need it because of the long requests.