Book Image

Learning Yeoman

By : Jonathan Spratley
Book Image

Learning Yeoman

By: Jonathan Spratley

Overview of this book

Table of Contents (17 chapters)
Learning Yeoman
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Modern Workflows for Modern Webapps
Index

Models


Models in an Ember application are associated with every route. Models are set up with data by either a route implementing the model property in a v view using the {{link-to}} helper, passing the model as an argument, or invoking a route's transitionTo method, passing the model as its argument.

Creating a model

To create a new model, use the ember:model subgenerator as follows:

$ yo ember:model Post title:string body:string image:string slug:string--coffee

The preceding command creates a new Ember model located at app/scripts/models/post_model.coffee.

By passing the name of the model and default attributes as property:type, they will be added to the model definition.

Methods

Models in Ember extend the Ember.Object class and are defined as DS.Model; there are many methods available for this class, but let's take a look at the most frequently used methods.

The following are the DS.Model methods:

  • changedAttributes: This will return the object with keys of changed properties and values of the...