Function

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

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

hasMany 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.
  • polymorphic A boolean value to mark the relationship as polymorphic

One-To-Many

To declare a one-to-many relationship between two models, use belongsTo in combination with hasMany, like this:

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

export default class PostModel extends Model {