Defining Ember model confusion - Ember.model vs DS.model vs Ember.Object


#1

This screencast : http://www.embercasts.com/episodes/getting-started-with-ember-model used Ember.model to create a person model like this:

App.Person = Ember.Model.extend({
	name : Ember.attr()
})

The docs give this example using Ember.Object

App.Person = Ember.Object.extend({
	say : function(thing) {
    	alert(thing);
	}
});

Further, under defining models section this example is given which uses DS.model

App.Person = DS.Model.extend({
  firstName: DS.attr('string'),
  lastName: DS.attr('string'),
  birthday: DS.attr('date'),

  fullName: function() {
    return this.get('firstName') + ' ' + this.get('lastName');
  }.property('firstName', 'lastName')
});

What is the difference between these three and when to use which?


#2

They all use different approaches / libraries for handling of data (models) in your application.

The first example is using a library called Ember Model - https://github.com/ebryn/ember-model . I don’t know a lot about it but it’s a reasonably light and simple approach to the data problem.

The second example is using plain ember objects as a model. In this example, you’d implement your own server interaction and likely build out a bit of infrastructure for making this consistent across models and their relationships. As far as I know, this is the approach that the guys who built discourse took - see this post by @eviltrout - http://eviltrout.com/2013/03/23/ember-without-data.html

The third example is based on Ember Data - https://github.com/emberjs/data

When to use each one is really a choice you need to make based on the needs of your app and the tradeoff between building a lot of stuff yourself or using something like Ember Data that is very good but still has some missing features and a few outstanding issues. Having said that, i’m using Ember Data with a lot of success at the moment and there’s a lot of work being put into it at the moment. All I can say is that in taking this route you will come up against issues but once you get past / understand them, you’re in a good place.

Another great option is the Ember Persistence Foundation. https://github.com/GroupTalent/epf …I’d highly recommend looking at this.

One problem that they all suffer at the moment IMO is a lack of documentation. Personally i’ve found this has been great for learning Ember Data more deeply but it’s not great if you just want to get on with it. This is an evolving space and it’s going to be really nice to work with once things stabilise and the apis get a bit more locked down.


#3

@jatin, did my answer on SO: http://stackoverflow.com/questions/18227614/using-ds-model-or-ember-model-or-ember-object-when-defining-a-model/ not satisfy your curiosity?


#4

@intuitivepixel You answer was surely helpful! I had actually asked on both places(SO and discourse) at the same time.