API Docs for: 0.1.0.ee3e9e64
Show:

AtomicSerializerMixin Class

Mixin that serializes uses Atomic Updates to only update fields that have been modified.

Atomic Updates can optionally include Optimistic Concurrency to ensure updates are not conflicting with other clients. See SolrAdapter.updateMode.

This implementation treats arrays as ordered and non-distinct. A multiValued field will be updated if the order of items changes or if any items are added or removed. The entire array will be sent using a set operation to preserve order and allow for duplicate values.

To treat multiValued fields as distinct sets, use AtomicMultiValuedSerializerMixin which will use add and remove operations.

Methods

applyTransforms

(
  • type
  • data
)
Object private

Given a subclass of DS.Model and a JSON object this method will iterate through each attribute of the DS.Model and invoke the DS.Transform#deserialize method on the matching property of the JSON object. This method is typically called after the serializer's normalize method.

Parameters:

  • type subclass of DS.Model
  • data Object

    <p>The data to transform</p>

Returns:

Object:

<p>data The transformed data object</p>

extract

(
  • store
  • type
  • payload
  • id
  • requestType
)
Object

The extract method is used to deserialize payload data from the server. By default the JSONSerializer does not push the records into the store. However records that subclass JSONSerializer such as the RESTSerializer may push records into the store as part of the extract call.

This method delegates to a more specific extract method based on the requestType.

Example

var get = Ember.get;
socket.on('message', function(message) {
  var modelName = message.model;
  var data = message.data;
  var type = store.modelFor(modelName);
  var serializer = store.serializerFor(type.typeKey);
  var record = serializer.extract(store, type, data, get(data, 'id'), 'single');
  store.push(modelName, record);
});

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object
  • id String or Number
  • requestType String

Returns:

Object:

<p>json The deserialized payload</p>

extractArray

(
  • store
  • type
  • payload
)
Array

extractArray is used to deserialize an array of records returned from the adapter.

Example

App.PostSerializer = DS.JSONSerializer.extend({
  extractArray: function(store, type, payload) {
    return payload.map(function(json) {
      return this.extractSingle(json);
    }, this);
  }
});

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Array:

<p>array An array of deserialized objects</p>

extractCreateRecord

(
  • store
  • type
  • payload
)
Object

extractCreateRecord is a hook into the extract method used when a call is made to DS.Store#createRecord. By default this method is alias for extractSave.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Object:

<p>json The deserialized payload</p>

extractDeleteRecord

(
  • store
  • type
  • payload
)
Object

extractDeleteRecord is a hook into the extract method used when a call is made to DS.Store#deleteRecord. By default this method is alias for extractSave.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Object:

<p>json The deserialized payload</p>

extractFind

(
  • store
  • type
  • payload
)
Object

extractFind is a hook into the extract method used when a call is made to DS.Store#find. By default this method is alias for extractSingle.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Object:

<p>json The deserialized payload</p>

extractFindAll

(
  • store
  • type
  • payload
)
Array

extractFindAll is a hook into the extract method used when a call is made to DS.Store#findAll. By default this method is an alias for extractArray.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Array:

<p>array An array of deserialized objects</p>

extractFindBelongsTo

(
  • store
  • type
  • payload
)
Object

extractFindBelongsTo is a hook into the extract method used when a call is made to DS.Store#findBelongsTo. By default this method is alias for extractSingle.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Object:

<p>json The deserialized payload</p>

extractFindHasMany

(
  • store
  • type
  • payload
)
Array

extractFindHasMany is a hook into the extract method used when a call is made to DS.Store#findHasMany. By default this method is alias for extractArray.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Array:

<p>array An array of deserialized objects</p>

extractFindMany

(
  • store
  • type
  • payload
)
Array

extractFindMany is a hook into the extract method used when a call is made to DS.Store#findMany. By default this method is alias for extractArray.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Array:

<p>array An array of deserialized objects</p>

extractFindQuery

(
  • store
  • type
  • payload
)
Array

extractFindQuery is a hook into the extract method used when a call is made to DS.Store#findQuery. By default this method is an alias for extractArray.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Array:

<p>array An array of deserialized objects</p>

extractMeta

(
  • store
  • type
  • payload
)

extractMeta is used to deserialize any meta information in the adapter payload. By default Ember Data expects meta information to be located on the meta property of the payload object.

Example

App.PostSerializer = DS.JSONSerializer.extend({
  extractMeta: function(store, type, payload) {
    if (payload && payload._pagination) {
      store.metaForType(type, payload._pagination);
      delete payload._pagination;
    }
  }
});

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

extractSave

(
  • store
  • type
  • payload
)
Object

extractSave is a hook into the extract method used when a call is made to DS.Model#save. By default this method is alias for extractSingle.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Object:

<p>json The deserialized payload</p>

extractSingle

(
  • store
  • type
  • payload
)
Object

extractSingle is used to deserialize a single record returned from the adapter.

Example

App.PostSerializer = DS.JSONSerializer.extend({
  extractSingle: function(store, type, payload) {
    payload.comments = payload._embedded.comment;
    delete payload._embedded;

    return this._super(store, type, payload);
  },
});

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Object:

<p>json The deserialized payload</p>

extractUpdateRecord

(
  • store
  • type
  • payload
)
Object

extractUpdateRecord is a hook into the extract method used when a call is made to DS.Store#update. By default this method is alias for extractSave.

Parameters:

  • store DS.Store
  • type subclass of DS.Model
  • payload Object

Returns:

Object:

<p>json The deserialized payload</p>

isAttributeModified

(
  • snapshot
  • key
  • attribtue
  • value
  • previousValue
)
Boolean

Determine if a value is modified from a previous value.

Parameters:

  • snapshot DS.Snapshot
  • key String
  • attribtue DS.Attribute
  • value Anything
  • previousValue Anything

Returns:

Boolean:

keyForAttribute

(
  • attr
)
String

Inherited from DS.JSONSerializer but overwritten in addon/serializers/solr.js:31

Converts attributes to underscore to use conventional Solr field names

Parameters:

Returns:

String:

<p>key</p>

keyForRelationship

(
  • key
  • relationship
)
String

keyForRelationship can be used to define a custom key when serializing relationship properties. By default JSONSerializer does not provide an implementation of this method.

Example

App.PostSerializer = DS.JSONSerializer.extend({
  keyForRelationship: function(key, relationship) {
     return 'rel_' + Ember.String.underscore(key);
  }
});

Parameters:

Returns:

String:

<p>normalized key</p>

normalize

(
  • type
  • hash
)
Object

Normalizes a part of the JSON payload returned by the server. You should override this method, munge the hash and call super if you have generic normalization to do.

It takes the type of the record that is being normalized (as a DS.Model class), the property where the hash was originally found, and the hash to normalize.

You can use this method, for example, to normalize underscored keys to camelized or other general-purpose normalizations.

Example

App.ApplicationSerializer = DS.JSONSerializer.extend({
  normalize: function(type, hash) {
    var fields = Ember.get(type, 'fields');
    fields.forEach(function(field) {
      var payloadField = Ember.String.underscore(field);
      if (field === payloadField) { return; }

      hash[field] = hash[payloadField];
      delete hash[payloadField];
    });
    return this._super.apply(this, arguments);
  }
});

Parameters:

  • type subclass of DS.Model
  • hash Object

Returns:

Object:

serialize

(
  • snapshot
  • options
)

Serialize only modified attributes for a snapshot using atomic update operations.

Parameters:

  • snapshot DS.Snapshot
  • options Object

serializeArrayAttribute

(
  • snapshot
  • key
  • attribute
  • value
  • previousValue
)
Object

Serialize an update to a multiValued field.

Parameters:

  • snapshot DS.Snapshot
  • key String
  • attribute DS.Attribute
  • value Anything
  • previousValue Anything

Returns:

Object:

serializeAttribute

(
  • snapshot
  • json
  • key
  • attribute
)

Determines if an attribute can be serialized and if the value is dirty.

Parameters:

  • snapshot DS.Snapshot
  • json Object
  • key String
  • attribute DS.Attribute

serializeBelongsTo

(
  • record
  • json
  • relationship
)

serializeBelongsTo can be used to customize how DS.belongsTo properties are serialized.

Example

App.PostSerializer = DS.JSONSerializer.extend({
  serializeBelongsTo: function(record, json, relationship) {
    var key = relationship.key;

    var belongsTo = get(record, key);

    key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo") : key;

    json[key] = Ember.isNone(belongsTo) ? belongsTo : belongsTo.toJSON();
  }
});

Parameters:

  • record DS.Model
  • json Object
  • relationship Object

serializeHasMany

(
  • record
  • json
  • relationship
)

serializeHasMany can be used to customize how DS.hasMany properties are serialized.

Example

App.PostSerializer = DS.JSONSerializer.extend({
  serializeHasMany: function(record, json, relationship) {
    var key = relationship.key;
    if (key === 'comments') {
      return;
    } else {
      this._super.apply(this, arguments);
    }
  }
});

Parameters:

  • record DS.Model
  • json Object
  • relationship Object

serializePolymorphicType

(
  • record
  • json
  • relationship
)

You can use this method to customize how polymorphic objects are serialized. Objects are considered to be polymorphic if {polymorphic: true} is pass as the second argument to the DS.belongsTo function.

Example

App.CommentSerializer = DS.JSONSerializer.extend({
  serializePolymorphicType: function(record, json, relationship) {
    var key = relationship.key,
        belongsTo = get(record, key);
    key = this.keyForAttribute ? this.keyForAttribute(key) : key;
    json[key + "_type"] = belongsTo.constructor.typeKey;
  }
});

Parameters:

  • record DS.Model
  • json Object
  • relationship Object

transformFor

(
  • attributeType
  • skipAssertion
)
DS.Transform private

Parameters:

  • attributeType String
  • skipAssertion Boolean

Returns:

DS.Transform:

<p>transform</p>

Properties

primaryKey

String

The primaryKey is used when serializing and deserializing data. Ember Data always uses the id property to store the id of the record. The external source may not always follow this convention. In these cases it is useful to override the primaryKey property to match the primaryKey of your external store.

Example

App.ApplicationSerializer = DS.JSONSerializer.extend({
                      primaryKey: '_id'
                    });
                    

Default: 'id'

versionFieldName

String

Field name to use for Solr Optimistic Concurrency. See Updating Parts of Documents.

Default: '_version_'