DS.BooleanTransform Class packages/ember-data/lib/transforms/boolean.js:3

The DS.BooleanTransform class is used to serialize and deserialize boolean attributes on Ember Data record objects. This transform is used when boolean is passed as the type parameter to the DS.attr function.

Usage

1
2
3
4
5
6
var attr = DS.attr;
App.User = DS.Model.extend({
  isAdmin: attr('boolean'),
  name: attr('string'),
  email: attr('string')
});
Show:

Methods

Show:

deserialize

(serialized) Mixed

When given a serialize value from a JSON object this method must return the deserialized value for the record attribute.

Example

1
2
3
deserialize: function(serialized) {
  return empty(serialized) ? null : Number(serialized);
}

Parameters:

serialized Mixed
The serialized value

Returns:

Mixed
The deserialized value

serialize

(deserialized) Mixed

When given a deserialized value from a record attribute this method must return the serialized value.

Example

1
2
3
serialize: function(deserialized) {
  return Ember.isEmpty(deserialized) ? null : Number(deserialized);
}

Parameters:

deserialized Mixed
The deserialized value

Returns:

Mixed
The serialized value