POST Only Specific Model Properties

Hi,

Using Ember Data to create a new record, I see that it’s serializing all the declared fields on my model. Normally, this is fine and desirable, but there are cases where I want to be able to control what is serialized and sent.

Is it possible to override the serialization behavior and if so, where might I start?

I am using the default ActiveModelSerializer

Thanks for any help.

Matt

Answering my own question here.

What I ended up doing was creating a specific serializer for the model that I need more control over.

So, if my model were a Post, I would have this:

App.PostSerializer = DS.ActiveModelSerializer.extend
  serialize: (post, options) ->
    json =
      content_id: post.get("content_id")
    if options.includeId?
      json.id = post.get("id")
    json

Hope this helps someone in the future.

2 Likes