Browse Source

[spod] Add record descriptor to cache to avoid infinite build loop with circular dependencies. See #3897

Cauê Waneck 10 years ago
parent
commit
5564cc2fae

+ 1 - 1
std/sys/db/RecordMacros.hx

@@ -283,6 +283,7 @@ class RecordMacros {
 			relations : [],
 			indexes : [],
 		};
+		g.cache.set(cname, i);
 		var c = c.get();
 		var fieldsPos = new haxe.ds.StringMap();
 		var fields = c.fields.get();
@@ -437,7 +438,6 @@ class RecordMacros {
 		// check primary key defined
 		if( i.key == null )
 			error("Table is missing unique id, use either SId, SUId, SBigID or @:id", c.pos);
-		g.cache.set(cname, i);
 		return i;
 	}
 

+ 1 - 0
tests/unit/src/unit/MySpodClass.hx

@@ -18,6 +18,7 @@ import sys.db.Types;
 
   @:relation(rid) public var relation:OtherSpodClass;
   @:relation(rnid) public var relationNullable:Null<OtherSpodClass>;
+	@:relation(spid) public var next:Null<MySpodClass>;
 
   public var data:SData<Array<ComplexClass>>;
   public var anEnum:SEnum<SpodEnum>;

+ 8 - 0
tests/unit/src/unit/TestSpod.hx

@@ -122,15 +122,21 @@ class TestSpod extends Test
 		c2.insert();
 
 		var scls = getDefaultClass();
+		var scls1 = scls;
 		scls.relation = c1;
 		scls.insert();
 		var id1 = scls.theId;
 		scls = getDefaultClass();
 		scls.relation = c1;
 		scls.insert();
+
+		scls1.next = scls;
+		scls1.update();
+
 		var id2 = scls.theId;
 		scls = getDefaultClass();
 		scls.relation = c1;
+		scls.next = scls1;
 		scls.anEnum = FirstValue;
 		scls.insert();
 		var id3 = scls.theId;
@@ -142,6 +148,8 @@ class TestSpod extends Test
 		var r2s = MySpodClass.manager.search($anEnum == FirstValue);
 		eq(r2s.length,1);
 		eq(r2s.first().theId,id3);
+		eq(r2s.first().next.theId,id1);
+		eq(r2s.first().next.next.theId,id2);
 
 		var fv = getSecond();
 		var r1s = [ for (c in MySpodClass.manager.search($anEnum == fv,{orderBy:theId})) c.theId ];