Models

basic model definition

import DS from 'ember-data';

const { Model } = DS;
const attr = DS.attr;
const hasMany = DS.hasMany;
const belongsTo = DS.belongsTo;

export default class TypedModel extends Model {
  @attr('string', { defaultValue: ''}) name! :string;
  @belongsTo('parent', { async: false }) parent! :DS.PromiseObject<Parent>;
  @hasMany('child', { async: true }) children! :DS.PromiseManyArray<Child>;
}

declare module 'ember-data/types/registries/model' {
  export default interface ModelRegistry {
    'typed-model': TypedModel;
  }
}

Models with ember-cp-validations

import DS from 'ember-data';
import { buildValidations } from 'ember-cp-validations';

const { Model } = DS;

const Validations = buildValidations({
  // validations go here
})

export default class TypedModel extends Model.extend(Validations) {

}

declare module 'ember-data/types/registries/model' {
  export default interface ModelRegistry {
    'typed-model': TypedModel;
  }
}

Inject Store Service

import StoreService from '@ember-data/store';

@service store! :StoreService;