Models

Standalone helpers to register and lookup model:${name} factories as well as to create model instances.

let models = store.models;

registerFactory(name, factory) → undefined

Registers a factory as model:${name} in Ember container.

  • nameString
  • factoryEmberObject class
models.registerFactory('duck', EmberObject.extend({ ... }));
let model = models.create('duck', { name: 'yellow' });
// → <foof@model:duck::ember1142>

hasFactoryFor(name) → Boolean

Returns true if model:${name} is registered.

  • nameString

factoryFor(name, { optional }) → Factory

Returns a model:${name} factory.

  • nameString
  • optionalBoolean (defaults to false)

If factory is not registered and optional is:

  • true → returns undefined
  • false → throws an assertation Error
let factory = models.FactoryFor('duck');
let model = factory.create{ name: 'yellow' });
// → <foof@model:duck::ember1142>

create(name, props) → Instance

Creates an instance.

  • nameString
  • propsObject

Throws an assertation Error if factory is not registered.

let factory = models.factoryFor('duck');
let model = factory.create{ name: 'yellow' });
// → <foof@model:duck::ember1142>