@attr
@attr
decorator is whatever Transform is applied via the invocation. See our overview of Transforms for more information.@attr
, the value is passed through without transformation.@attr('string')
→ string
@attr('number')
→ number
@attr('boolean')
→ boolean
@attr('date')
→ Date
?
or definitely present (no annotation): Ember Data will default to leaving a property empty if it is not supplied by the API or by a developer when creating it. That is: the default for Ember corresponds to an optional field on the model.?
, you should take care to guarantee that this is a guarantee your API upholds, and that ever time you create a record from within the app, you uphold those guarantees.defaultValue
on the options hash for the attribute:import User from './user';
. This, naturally, can cause a recursive loop, as /app/models/post.ts
imports User
from /app/models/user.ts
, and /app/models/user.ts
imports Post
from /app/models/post.ts
. Recursive importing triggers an import/no-cycle
error from eslint.@belongsTo
@belongsTo
decorator depends on whether the relationship is { async: true }
(which it is by default).true
, the type you should use is AsyncBelongsTo<Model>
, where Model
is the type of the model you are creating a relationship to.false
, the type is Model
, where Model
is the type of the model you are creating a relationship to.?
optional marker:AsyncBelongsTo<Model>
object, which itself may or may not ultimately resolve to a value—depending on the API response—but will always be present itself.@hasMany
@hasMany
decorator depends on whether the relationship is { async: true }
(which it is by default).true
, the type you should use is AsyncHasMany<Model>
, where Model
is the type of the model you are creating a relationship to.false
, the type is SyncHasMany<Model>
, where Model
is the type of the model you are creating a relationship to.@belongsTo
apply to these types. The difference is just that in @hasMany
the resulting types are arrays rather than single objects.