Question

It seems that JayData EntitySet does not catch property changes when set through Ember like this:

//init at start
controller.set('todo', todoDB.Todos.attachOrGet({ Id:1}));

//later in app 
controller.set('todo.Completed', true);

//in the end
todoDB.saveChanges();

I tried this:

controller.todo.save();

But it didnt work!

Then I finally managed with this HACK(?):

var self = this;
mdefs = self.get('todo').getType().memberDefinitions;

for (var name in mdefs) {
   if (mdefs[name] 
       && mdefs[name].kind == "property" 
       && mdefs[name].definedBy == self.todo.getType())
      self.todo._setPropertyChanged(mdefs[name]);
}

self.get('todo').save();

So my question is... Is there any pretty(ish) way to do this?

Edit

look at @kingpin2k 's anwer bellow and the comments!

it turns out to be (apparently) only happening with an OData provider (havent tested others). couldnt reproduce with WebSQL.

Was it helpful?

Solution

The setter is invalid, you are setting todo to undefined.

//init at start
controller.set('todo',  todoDB.Todos.attachOrGet({ Id:1}));

http://emberjs.jsbin.com/AyIMIBi/1/edit

With remove and completed

http://emberjs.jsbin.com/AyIMIBi/2/edit

Additionally, tho unnecessary, if you were trying to grab the todo off the controller, you should use a getter.

controller.get('todo').save();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top