O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining models

In the introductory chapters, we learned how to organize application objects into reusable classes called models. Ember-data provides support for defining such models that extend DS.Model, and from which records can then be created. For example, let's review the Todo model that was defined in the samples:

App.Todo = DS.Model.extend({
  title: DS.attr('string'),
  complete: DS.attr('boolean', {
    defaultValue: false
  })
});

As illustrated, the model was defined by extending the DS.Model class. We then defined two attributes using the DS.attr class methods that take two arguments:

  • The name of the attribute
  • An optional options object

The attribute's type is usually one of the following:

  • String
  • Number
  • Date
  • Boolean

However, we learn later that it's ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required