Browse Source

change in spec/impl for SData : serialize again as soon as readed (allow mutation
of structures)

Nicolas Cannasse 13 years ago
parent
commit
263a052a21
2 changed files with 7 additions and 7 deletions
  1. 3 3
      std/sys/db/Manager.hx
  2. 4 4
      std/sys/db/SpodMacros.hx

+ 3 - 3
std/sys/db/Manager.hx

@@ -120,10 +120,10 @@ class Manager<T : Object> {
 	/* -------------------------- SPODOBJECT API -------------------------- */
 
 	function doUpdateCache( x : T, name : String ) {
-		var cache : { v : Dynamic, m : Bool } = Reflect.field(x, "cache_" + name);
+		var cache : { v : Dynamic } = Reflect.field(x, "cache_" + name);
 		var v = doSerialize(name, cache.v);
-		Reflect.setField(x, name, v);
-		cache.m = false;
+		// don't set it since the value might change again later
+		// Reflect.setField(x, name, v);
 		return v;
 	}
 	

+ 4 - 4
std/sys/db/SpodMacros.hx

@@ -1219,16 +1219,16 @@ class SpodMacros {
 								args : [],
 								params : [],
 								ret : t,
-								expr : macro { if( $ecache == null ) $ecache = { v : untyped manager.doUnserialize($fname,cast $efield), m : false }; return $ecache.v; },
+								// we set efield to an empty object to make sure it will be != from previous value when insert/update is triggered
+								expr : macro { if( $ecache == null ) { $ecache = { v : untyped manager.doUnserialize($fname, cast $efield) }; Reflect.setField(this, $fname, { } ); }; return $ecache.v; },
 							};
 							var set = {
 								args : [{ name : "_v", opt : false, type : t, value : null }],
 								params : [],
 								ret : t,
-								// set efield to an empty object to make sure it will be != from previous value when insert/update is triggered
-								expr : macro { if( $ecache == null || !$ecache.m ) { $ecache = { v : _v, m : true }; $efield = cast { }; } else $ecache.v = _v; return _v; },
+								expr : macro { if( $ecache == null ) { $ecache = { v : _v }; $efield = cast {}; } else $ecache.v = _v; return _v; },
 							};
-							fields.push( { name : cache, pos : pos, meta : [meta[0], { name:":skip", params:[], pos:pos } ], access : [APrivate], doc : null, kind : FVar(macro : { v : $t, m : Bool }, null) } );
+							fields.push( { name : cache, pos : pos, meta : [meta[0], { name:":skip", params:[], pos:pos } ], access : [APrivate], doc : null, kind : FVar(macro : { v : $t }, null) } );
 							fields.push( { name : "get_" + f.name, pos : pos, meta : meta, access : [APrivate], doc : null, kind : FFun(get) } );
 							fields.push( { name : "set_" + f.name, pos : pos, meta : meta, access : [APrivate], doc : null, kind : FFun(set) } );
 						}