1

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.

Community
  • 1
  • 1
Jmorvan
  • 1,020
  • 11
  • 31
  • Could you try to instantiate your entity with 'new' ? like var todo = new todoDB.Todos.elementType({Id:1}); and then you can either add it to the context or set its entityState to $data.EntityState.Modified. Your hack is unnecessary, it should just work – Gabor Dolla Dec 15 '13 at 09:59
  • thanks @GaborDolla! thats actually what I do in my app! the above was just a poor attempt to explain my issue. In reality _changedProperties is not updated when set through ember set with the OdataProvider. it works if I set it explicitly though. Do you want me to file an issue on GitHub? – Jmorvan Dec 15 '13 at 20:08
  • Could you create a jsfiddle instead if filing an issue? – Gabor Dolla Dec 15 '13 at 20:45
  • It should be independent of the provider used. – Gabor Dolla Dec 15 '13 at 20:46
  • @GaborDolla, I just created a fiddle to try reproduce http://jsfiddle.net/jmorvan/K5Cra/ . but no luck! the only difference I can see is the provider I use which per your last comment should't make a difference. I dont have the time nor the ressources at the moment for setting up a dummy wcf service to test with so I'll just leave it as is for now. it still seems weird to me! must be something wrong with my code then! – Jmorvan Dec 17 '13 at 10:24
  • I will take a look later today – Gabor Dolla Dec 17 '13 at 10:43
  • @GaborDolla did you have any luck with this? I am still having this issue on odata/emberJS – Jmorvan Jan 24 '14 at 15:18

1 Answers1

1

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();
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
  • It is the point, you are setting a reference to a todo on the controller, but you aren't setting it, then when you try and use the todo later you are setting values on something completely different. And where on his homepage did you copy that from? – Kingpin2k Dec 13 '13 at 23:07
  • Oh!! I get it! just saw your profile... you are an Ember fanatic! I understand now. no worries ;-) – Jmorvan Dec 13 '13 at 23:23
  • you mean without the hack? – Jmorvan Dec 13 '13 at 23:46
  • yup, i added both examples in my answer. – Kingpin2k Dec 13 '13 at 23:48
  • 1
    Pardon the ugliness, just had shoulder surgery and css is too much work one handed. – Kingpin2k Dec 13 '13 at 23:49
  • What is CSS? Its fine! actually its great! I usually only use jaydata with odata through WCF and it would have been too tricky to just list my entities and open a server for test so I copied some simple code! I still have my issue but thanks to you I found out it only happened on OdataProvider. I dont know why though! the only thing i can see is that `_changedProperties` is not populated when i save to default provider but they are through oData. that would make sense since my hack did just this! anyway thanks again! that was good for a one handed! – Jmorvan Dec 14 '13 at 00:36