@belongsTo

Declares a one-to-one or many-to-one relationship on a model.

Since Ember 4/5 (Octane) Spec ↗

Syntax

@belongsTo('type', { async, inverse })

Returns

PropertyDecorator — A related record reference.

Examples

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

export default class CommentModel extends Model {
  @attr('string') body;
  @belongsTo('post', { async: true, inverse: 'comments' }) post;
  @belongsTo('user', { async: false, inverse: null }) author;
}

Notes

With async: true the relationship is a PromiseProxy that loads on access; with async: false it must already be loaded. Always set `inverse` (or null) so EmberData can maintain both sides correctly.