Browse Source

fix rare issue with relations + transactions

Nicolas Cannasse 16 years ago
parent
commit
0c5ea905b0
2 changed files with 8 additions and 1 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 7 1
      std/neko/db/Manager.hx

+ 1 - 0
doc/CHANGES.txt

@@ -27,6 +27,7 @@ TODO :
 	all : forbid same name for static+instance field (not supported on several platforms)
 	all : forbid same name for static+instance field (not supported on several platforms)
 	all : renamed haxe.Http.request to "requestUrl"
 	all : renamed haxe.Http.request to "requestUrl"
 	all : renamed neko.zip.Compress/Uncompress.run to "execute"
 	all : renamed neko.zip.Compress/Uncompress.run to "execute"
+	spod : fix very rare issue with relations and transactions
 
 
 2009-03-22: 2.03
 2009-03-22: 2.03
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php

+ 7 - 1
std/neko/db/Manager.hx

@@ -469,7 +469,13 @@ class Manager<T : Object> {
 			var f = Reflect.field(othis,hprop);
 			var f = Reflect.field(othis,hprop);
 			if( f != null )
 			if( f != null )
 				return f;
 				return f;
-			f = manager.get(Reflect.field(othis,hkey),lock);
+			var id = Reflect.field(othis,hkey);
+			f = manager.get(id,lock);
+			// it's highly possible that in that case the object has been inserted
+			// after we started our transaction : in that case, let's lock it, since
+			// it's still better than returning 'null' while it exists
+			if( f == null && id != null && !lock )
+				f = manager.get(id,true);
 			Reflect.setField(othis,hprop,f);
 			Reflect.setField(othis,hprop,f);
 			return f;
 			return f;
 		});
 		});