Skip to content

Instantly share code, notes, and snippets.

@wagenet
Last active December 12, 2015 08:08
Show Gist options
  • Select an option

  • Save wagenet/4741222 to your computer and use it in GitHub Desktop.

Select an option

Save wagenet/4741222 to your computer and use it in GitHub Desktop.
DS.Adapter.registerTransform('object', {
serialize: function(obj) { return obj; },
deserialize: function(obj) { return obj; }
});
MyApp.MyModel = DS.Model.extend({
location: DS.attr('object')
});
var model = MyApp.Model.createRecord({ location: { lat: 123, lng: 456 } });
model.save();
model.set('location.lat', 789);
model.get('isDirty'); // false
// Normally this happens automatically, but in this case you're setting the contents of an object so Ember Data doesn't see the
model.attributeWillChange(model, 'location');
model.set('location.lat', 789);
// Paired with above
model.attributeDidChange(model, 'location');
model.get('isDirty'); // true
@wagenet
Copy link
Author

wagenet commented Feb 8, 2013

It's actually worth seeing if, instead of calling attributeWillChange and attributeDidChange, if just resetting location to itself works, i.e. model.set('location', model.get('location')). I'm not sure that this alternative will work though since Ember Data might not think it was an actual change since the object is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment