@attr

Declares a persisted attribute on an EmberData model.

Since Ember 4/5 (Octane) Spec ↗

Syntax

@attr('type', { defaultValue })

Returns

PropertyDecorator — A tracked, persisted model field.

Examples

import Model, { attr } from '@ember-data/model';

export default class UserModel extends Model {
  @attr('string') name;
  @attr('number') age;
  @attr('boolean', { defaultValue: false }) verified;
  @attr('date') createdAt;
}

Notes

Built-in transforms are string, number, boolean, and date; omit the type for raw JSON values. Use defaultValue (a value or a function) for new records. Attributes are tracked, so templates update automatically.