Documentation / @ember-data/serializer / transform / BooleanTransform
Defined in: packages/serializer/src/-private/transforms/boolean.ts:38
The 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 attr function.
Usage
import Model, { attr } from '@ember-data/model';
export default class UserModel extends Model {
@attr('boolean') isAdmin;
@attr('string') name;
@attr('string') email;
}
By default, the boolean transform only allows for values of true
or false
. You can opt into allowing null
values for boolean attributes via attr('boolean', { allowNull: true })
import Model, { attr } from '@ember-data/model';
export default class UserModel extends Model {
@attr('string') email;
@attr('string') username;
@attr('boolean', { allowNull: true }) wantsWeeklyEmail;
}
BooleanTransform
Constructors
Constructor
new BooleanTransform(): BooleanTransform;
Returns
BooleanTransform
Properties
___(unique) Symbol($type)
___(unique) Symbol($type): "boolean";
Defined in: packages/serializer/src/-private/transforms/boolean.ts:63
Methods
deserialize()
deserialize(serialized, options?): null | boolean;
Defined in: packages/serializer/src/-private/transforms/boolean.ts:39
Parameters
serialized
null
| string
| number
| boolean
options?
allowNull?
boolean
Returns
null
| boolean
serialize()
serialize(deserialized, options?): null | boolean;
Defined in: packages/serializer/src/-private/transforms/boolean.ts:55
Parameters
deserialized
null
| boolean
options?
allowNull?
boolean
Returns
null
| boolean
create()
static create(): BooleanTransform;
Defined in: packages/serializer/src/-private/transforms/boolean.ts:65
Returns
BooleanTransform