Function

modelName
String
(optional) type of the relationship
options
Object
(optional) a hash of options
returns
Ember.computed
relationship

belongsTo is used to define One-To-One and One-To-Many relationships on a Model.

belongsTo takes an optional hash as a second parameter, currently supported options are:

  • async: A boolean value used to explicitly declare this to be an async relationship. The default is true.
  • inverse: A string used to identify the inverse property on a related model in a One-To-Many relationship. See Explicit Inverses
  • polymorphic A boolean value to mark the relationship as polymorphic

One-To-One

To declare a one-to-one relationship between two models, use belongsTo:

app/models/user.js
1
2
3
import Model, { belongsTo } from '@ember-data/model';

export default class UserModel extends Model {