Skip to content

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

app/models/user.js
js
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 })

app/models/user.js
js
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

ts
new BooleanTransform(): BooleanTransform;

Returns

BooleanTransform

Properties

___(unique) Symbol($type)

ts
___(unique) Symbol($type): "boolean";

Defined in: packages/serializer/src/-private/transforms/boolean.ts:63

Methods

deserialize()

ts
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()

ts
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()

ts
static create(): BooleanTransform;

Defined in: packages/serializer/src/-private/transforms/boolean.ts:65

Returns

BooleanTransform

Released under the MIT License.