Matt Blair

Matt Blair

I read that you learn more from a poor example than from a correct one. I don't believe this but that means my site will be a success.

Ember Model.isDirty - or not

Ember Model.isDirty - or not

1-Minute Read

In Ember, if you have models like this:

  var Tag = DS.Model.extend({
    name: DS.attr('string'),
    person: DS.belongsTo('person')
  });

  var Person = DS.Model.extend({
    name: DS.attr('string'),
    tags: DS.hasMany('tag')
  });

Then did something like this:

var tag1 = this.store.find('tag', 1);

tag1.get('isDirty'); //returns false
tag1.get('name'); //return null
tag1.set('name', 'foo');
tag1.get('isDirty'); //returns true

That would be the obvious outcome, right?

However, if you do this:

var tag1 = this.store.find('tag', 1);
var thatGuy = this.store.find('person', 1);

tag1.get('isDirty'); //returns false
tag.get('person'); //returns null
tag1.set('person', thatGuy); //set person on tag
tag1.get('isDirty'); //returns false

Because Ember does not check relationships when figuring out isDirty.

Here is the issue on github

Here is a solution proposed by someone else (that I do not think solves the problem)

Recent Posts

Categories

About

This theme was developed for Hugo.