Defining Models

A model is a class that defines the properties and behavior of the
data that you present to the user. Anything that the user expects to see
if they leave your app and come back later (or if they refresh the page)
should be represented by a model.

When you want a new model for your application you need to create a new file
under the models folder and extend from DS.Model. This is more conveniently
done by using one of Ember CLI's generator commands. For instance, let's create
a person model:

Transforms

You may find the type of an attribute returned by the server does not
match the type you would like to use in your JavaScript code. Ember
Data allows you to define simple serialization and deserialization
methods for attribute types called transforms. You can specify that
you would like a transform to run for an attribute by providing the
transform name as the first argument to the DS.attr method. Ember Data
supports attribute types of string, number, boolean, and date,
which coerce the value to the JavaScript type that matches its name.

A transform has two functions: serialize and deserialize. Deserialization
converts a value to a format that the client expects. Serialization does the
reverse and converts a value to the format expected by the persistence layer.

Options

DS.attr can also take a hash of options as a second parameter. At the moment
the only option available is defaultValue, which can use a value or a function
to set the default value of the attribute if one is not supplied.

In the following example we define that verified has a default value of
false and createdAt defaults to the current date at the time of the model's
creation: