Browse Source

[spod] Fix typing errors on relations

Cauê Waneck 11 years ago
parent
commit
d59773a47a
2 changed files with 66 additions and 62 deletions
  1. 5 3
      std/sys/db/Manager.hx
  2. 61 59
      std/sys/db/RecordMacros.hx

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

@@ -560,6 +560,7 @@ class Manager<T : Object> {
 		var lock = r.lock;
 		if( manager == null || manager.table_keys == null ) throw ("Invalid manager for relation "+table_name+":"+r.prop);
 		if( manager.table_keys.length != 1 ) throw ("Relation " + r.prop + "(" + r.key + ") on a multiple key table");
+#if neko
 		Reflect.setField(class_proto.prototype,"get_"+r.prop,function() {
 			var othis = untyped __this__;
 			var f = Reflect.field(othis,hprop);
@@ -583,6 +584,7 @@ class Manager<T : Object> {
 			Reflect.setField(othis,hkey,Reflect.field(f,manager.table_keys[0]));
 			return f;
 		});
+#end
 	}
 
 	#if !neko
@@ -590,14 +592,14 @@ class Manager<T : Object> {
 	function __get( x : Dynamic, prop : String, key : String, lock ) {
 		var v = Reflect.field(x,prop);
 		if( v != null )
-			return v.value;
+			return v;
 		var y = unsafeGet(Reflect.field(x, key), lock);
-		Reflect.setField(x,prop,{ value : y });
+		Reflect.setField(x,prop,v);
 		return y;
 	}
 
 	function __set( x : Dynamic, prop : String, key : String, v : T ) {
-		Reflect.setField(x,prop,{ value : v });
+		Reflect.setField(x,prop,v);
 		if( v == null )
 			Reflect.setField(x,key,null);
 		else

+ 61 - 59
std/sys/db/RecordMacros.hx

@@ -1244,68 +1244,70 @@ class RecordMacros {
 					skip = true;
 				case ":relation":
 					switch( f.kind ) {
-					case FVar(t, _):
-						f.kind = FProp("dynamic", "dynamic", t);
-						if( isNeko )
-							continue;
-						// create compile-time getter/setter for other platforms
-						var relKey = null;
-						var relParams = [];
-						var lock = false;
-						for( p in m.params )
-							switch( p.expr ) {
-							case EConst(c):
-								switch( c ) {
-								case CIdent(i):
-									relParams.push(i);
+						case FVar(t, _):
+							f.kind = FProp("dynamic", "dynamic", t);
+							if( isNeko )
+								continue;
+							// create compile-time getter/setter for other platforms
+							var relKey = null;
+							var relParams = [];
+							var lock = false;
+							for( p in m.params )
+								switch( p.expr ) {
+								case EConst(c):
+									switch( c ) {
+									case CIdent(i):
+										relParams.push(i);
+									default:
+									}
 								default:
 								}
-							default:
-							}
-						relKey = relParams.shift();
-						for( p in relParams )
-							if( p == "lock" )
-								lock = true;
-						// we will get an error later
-						if( relKey == null )
-							continue;
-						// generate get/set methods stubs
-						var pos = f.pos;
-						var ttype = t, tname;
-						while( true )
-							switch(ttype) {
-							case TPath(t):
-								if( t.params.length == 1 && (t.name == "Null" || t.name == "SNull") ) {
-									ttype = switch( t.params[0] ) {
-									case TPType(t): t;
-									default: throw "assert";
-									};
-									continue;
+							relKey = relParams.shift();
+							for( p in relParams )
+								if( p == "lock" )
+									lock = true;
+							// we will get an error later
+							if( relKey == null )
+								continue;
+							// generate get/set methods stubs
+							var pos = f.pos;
+							var ttype = t, tname;
+							while( true )
+								switch(ttype) {
+								case TPath(t):
+									if( t.params.length == 1 && (t.name == "Null" || t.name == "SNull") ) {
+										ttype = switch( t.params[0] ) {
+										case TPType(t): t;
+										default: throw "assert";
+										};
+										continue;
+									}
+									var p = t.pack.copy();
+									p.push(t.name);
+									if( t.sub != null ) p.push(t.sub);
+									tname = p.join(".");
+									break;
+								default:
+									Context.error("Relation type should be a type path", f.pos);
 								}
-								var p = t.pack.copy();
-								p.push(t.name);
-								if( t.sub != null ) p.push(t.sub);
-								tname = p.join(".");
-								break;
-							default:
-								Context.error("Relation type should be a type path", f.pos);
-							}
-						function e(expr) return { expr : expr, pos : pos };
-						var get = {
-							args : [],
-							params : [],
-							ret : t,
-							expr : Context.parse("return untyped "+tname+".manager.__get(this,'"+f.name+"','"+relKey+"',"+lock+")",pos),
-						};
-						var set = {
-							args : [{ name : "_v", opt : false, type : t, value : null }],
-							params : [],
-							ret : t,
-							expr : Context.parse("return untyped "+tname+".manager.__set(this,'"+f.name+"','"+relKey+"',_v)",pos),
-						};
-						var meta = [{ name : ":hide", params : [], pos : pos }];
-						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) });
+							function e(expr) return { expr : expr, pos : pos };
+							var get = {
+								args : [],
+								params : [],
+								ret : t,
+								expr : Context.parse("return untyped "+tname+".manager.__get(this,'"+f.name+"','"+relKey+"',"+lock+")",pos),
+							};
+							var set = {
+								args : [{ name : "_v", opt : false, type : t, value : null }],
+								params : [],
+								ret : t,
+								expr : Context.parse("return untyped "+tname+".manager.__set(this,'"+f.name+"','"+relKey+"',_v)",pos),
+							};
+							var meta = [{ name : ":hide", params : [], pos : pos }];
+							f.meta.push({ name: ":isVar", params : [], pos : pos });
+							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) });
+							fields.push({ name : relKey, pos : pos, meta : [{ name : ":skip", params : [], pos : pos }], access : [APrivate], doc : null, kind : FVar(macro : Dynamic) });
 					default:
 						Context.error("Invalid relation field type", f.pos);
 					}