iphone - MonoTouch CoolStorage OneToMany caching issue -
i'm experiencing issue coolstorage onetomany relationship being cached when reading list first time, list fails update when data changes later.
when restarting app list correct, must caching issue , can't find solution in coolstorage documentation or anywhere.
i've pasted unit test code below.
i have game class has opponent of type person. there many games, , person can opponent many games.
my person class has cslist
called opponentgames, @ anytime person can 'get games person opponent'.
in unit test first time reference 'person.opponentgames.count', correctly tells me there 1 game. after creating second game , adding person opponent, still reports 1 game opponentgames.
if remove first count, test passes, first check result being cached , there it's not updated.
i'll appreciate suggestions!! thanks.
the sql (sqlite3)
setup:
csdatabase.executenonquery( "create table person " + "(serverid integer primary key)"); csdatabase.executenonquery( "create table game " + "(serverid integer primary key," + "opponentid integer references user(serverid))");
the coolstorage .net classes:
[mapto("game")] public class game : csobject<game,int> { //[primarykey] public int serverid { { return (int) getfield("serverid"); } set { setfield("serverid", value); } } [manytoone (localkey="opponentid", foreignkey="serverid")] public person opponent { { return (person) getfield("opponent"); } set { setfield("opponent", value); } } } [mapto("person")] public class person : csobject<person,int> { //[primarykey] public int serverid { { return (int) getfield("serverid"); } set { setfield("serverid", value); } } [onetomany (localkey="serverid", foreignkey="opponentid")] public cslist<game> opponentgames { { return (cslist<game>) getfield("opponentgames"); } } }
and finally, unit test:
// user person person = person.new (); person.serverid = 1; // first game game game = game.new (); game.serverid = 1; game.opponent = person; game.save (); person.save (); // line correctly returns 1, removing passes test console.writeline ("count0: " + person.opponentgames.count); // second game game game2 = game.new (); game2.serverid = 2; game2.opponent = person; game2.save (); person.save (); // incorrectly shows 1, should 2 console.writeline ("count1: " + person.opponentgames.count); // , fails assert.true (person.opponentgames.count == 2);
Comments
Post a Comment