PDA

View Full Version : [CLOSED] store.add() does nothing



dr-dan
13 Feb 2013, 6:53 AM
given
mystore (a store)


console.log(mystore.getCount()) // == 4
store.add(model);
console.log(mystore.getCount()) // == 4

No error reported.

== a revert back to 4.1 (which works)

13 Feb 2013, 7:27 AM
given
mystore (a store)


Might need a little more code then that to help you troubleshoot. It seems to work fine for me using the latest nightly: v4.2.0.449

dr-dan
13 Feb 2013, 8:12 AM
I have boiled it down to the fact that I am adding two objects with the same "unassigned" Id of "0"

Its zero as it will get assigned an id by the server on update. If I update it to be "null" then it works ok. Like I said this was unnecessary with 4.1 so it's a breaking change.


var rs = Ext.create("Pegfect.model.profile.ResponseSet");
var m1 = Ext.create("Pegfect.model.profile.Response", { Id: null});
var m2 = Ext.create("Pegfect.model.profile.Response", { Id: null });


var hc = [m1, m2];
rs.responses().removeAll();
rs.responses().add(hc);
console.log("hc arr:" + hc.length); //==2
console.log("hc rs:" + rs.responses().getCount()); //==2



var rs = Ext.create("Pegfect.model.profile.ResponseSet");
var m1 = Ext.create("Pegfect.model.profile.Response", { Id: 0});
var m2 = Ext.create("Pegfect.model.profile.Response", { Id: 0});


var hc = [m1, m2];
rs.responses().removeAll();
rs.responses().add(hc);
console.log("hc arr:" + hc.length); //==2
console.log("hc rs:" + rs.responses().getCount()); //==1

evant
13 Feb 2013, 1:13 PM
This is something we won't be fixing. As you suggested, there's a difference between 0 & null. Users have pointed out that 0, although typically not used as an identifier, still represents an explicitly assigned value for an id, so it should be treated as a non-phantom value. Null/undefined values still are treated as phantoms and as such are assigned their own default identifiers.

dr-dan
14 Feb 2013, 12:25 AM
imo the rules as to what makes a record new or existing should not be hard-coded into the framework.

isNew() config function perhaps?

Would you consider putting that in your release notes so that others don't have to find out the hard way?