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.
Item Index
Methods
- applyTransforms
- extract
- extractArray
- extractCreateRecord
- extractDeleteRecord
- extractFind
- extractFindAll
- extractFindBelongsTo
- extractFindHasMany
- extractFindMany
- extractFindQuery
- extractMeta
- extractSave
- extractSingle
- extractUpdateRecord
- isAttributeModified
- keyForAttribute
- keyForRelationship
- normalize
- serialize
- serializeArrayAttribute
- serializeAttribute
- serializeBelongsTo
- serializeHasMany
- serializePolymorphicType
- transformFor
Properties
Methods
applyTransforms
-
type -
data
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:
-
typesubclass of DS.Model -
dataObjectThe data to transform
Returns:
data The transformed data object
extract
-
store -
type -
payload -
id -
requestType
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:
Returns:
json The deserialized payload
extractArray
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
array An array of deserialized objects
extractCreateRecord
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
json The deserialized payload
extractDeleteRecord
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
json The deserialized payload
extractFind
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
json The deserialized payload
extractFindAll
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
array An array of deserialized objects
extractFindBelongsTo
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
json The deserialized payload
extractFindHasMany
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
array An array of deserialized objects
extractFindMany
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
array An array of deserialized objects
extractFindQuery
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
extractSave
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
json The deserialized payload
extractSingle
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
json The deserialized payload
extractUpdateRecord
-
store -
type -
payload
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:
-
storeDS.Store -
typesubclass of DS.Model -
payloadObject
Returns:
json The deserialized payload
isAttributeModified
()
Uses "set arithmetic" to detect modifications for arrays or delegates to base implementation for non-arrays.
keyForAttribute
-
attr
Converts attributes to underscore to use conventional Solr field names
Parameters:
-
attrString
Returns:
key
keyForRelationship
-
key -
relationship
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);
}
});
Returns:
normalized key
normalize
-
type -
hash
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:
-
typesubclass of DS.Model -
hashObject
Returns:
serialize
-
snapshot -
options
Serialize only modified attributes for a snapshot using atomic update operations.
Parameters:
-
snapshotDS.Snapshot -
optionsObject
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:
-
snapshotDS.Snapshot -
jsonObject -
keyString -
attributeDS.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:
-
recordDS.Model -
jsonObject -
relationshipObject
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:
-
recordDS.Model -
jsonObject -
relationshipObject
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:
-
recordDS.Model -
jsonObject -
relationshipObject
transformFor
-
attributeType -
skipAssertion
Parameters:
-
attributeTypeString -
skipAssertionBoolean
Returns:
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_'
