API Docs for: 0.1.0.ee3e9e64
Show:

AtomicMultiValuedSerializerMixin Class

Mixin that extends AtomicSerializerMixin to use Atomic Updates with add and remove operations for array changes.

This implementation treats arrays as unordered and distinct. A multiValued field will be updated any items are added or removed. Only values that have been added or removed are sent, using the add or remove operations respectively.

Note that the remove operation requires Solr 5 or later.

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

    The data to transform

Returns:

Object:

data The transformed data object

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:

json The deserialized payload

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:

array An array of deserialized objects

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:

json The deserialized payload

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:

json The deserialized payload

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:

json The deserialized payload

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:

array An array of deserialized objects

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:

json The deserialized payload

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:

array An array of deserialized objects

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:

array An array of deserialized objects

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:

array An array of deserialized objects

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:

json The deserialized payload

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:

json The deserialized payload

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:

json The deserialized payload

isAttributeModified

()

Uses "set arithmetic" to detect modifications for arrays or delegates to base implementation for non-arrays.

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:

key

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:

normalized key

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

()

Uses "set arithmetic" to calculate add and remove operations for arrays.

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:

transform

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_'