An Ember Ecosystem
For Spree Commerce

spree-ember-core

Extends DS.ActiveModelSerializer

The Spree Serializer is based on the DS.ActiveModelSerializer, but implements a stricter serialize method.

var model = DS.Model.extend({
  firstName: DS.attr("string", { persistToServer: true }),
  lastName: DS.attr("string")
});

var hugh = model.create();

hugh.setProperties({
  firstName: "Hugh",
  lastName: "Francis"
});

spreeSerializer.serialize(hugh);
// => Results in payload:
user: {
  first_name: "Hugh"
}

Methods

Show Private Methods

serialize

(
  • record
)

Serializes a record for sending to the Spree server. Here, we extend the default behaviour of DS.ActiveModelSerializer#serialize to ensure that we only persist attributes & relationships that have persistToServer: true in the model definition. We also add the id to the payload, as we're often sending nested models to the server.

Parameters:

  • record DS.Model

    A model to serialize.


Returns:

Object:

A JSON object representing the record.