spod macros relations

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

spod macros relations

postite
hell everybody,

id don't get the point with spodmacros relations.

i use to to it with regular spods .. but i got lost with the macros ones.

the doc says :

class User extends sys.db.Object {
     public var id : SId;
     // ....
}
class Group extends sys.db.Object {
   public var id : SId;
   // ...
}

@:id(gid,uid)
class UserGroup extends sys.db.Object {
     @:relation(uid) public var user : User;
     @:relation(gid) public var group : Group;
}

ok ..

now i just gave a try ..

my spod bebe 
@:table ('bebe')
@:id(id)
class Bebe extends sys.db.Object , implements Spodable{
public var id : SId;
    public var titre : SString<255>;
@:relation(rid) public var rel:Papa;
//tried @:relation(rid) public var rel(dynamic,dynamic):Papa; //causes error invalid relation field type
}

and another spod

@:table ('papa') @:id(id) class Papa extends sys.db.Object , implements Spodable{ public var id : SId; public var titre : SString<255>; @:skip public var bebeliste:List<Bebe>;

// will use it to populate bebeliste with make() and unmake() public static var manager:Manager<Papa>= new Manager<Papa>(Papa);  }



in my Main class:

public function new()
{
var db = new Database(); /// set the connection
var b=new vo.Bebe();
b.titre="girl";
var papa=vo.Papa.manager.get(1); //retrieve existing Papa entry
trace(papa.titre);
b.rel=papa; // causes error invalid call
b.insert();

}

if someone could explain or correct my code ... i would be pleased to modify the doc to make it more explicit .

Thanks

postite

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

Blue Sans douze
b.rel=papa; // causes error invalid call
It's incorrect.

What you can do is modify the Bebe class and add that :
public var rid:Int;

Then :
b.rid = papa.id;

It should do the trick.
Blue112.

2011/9/29 david <[hidden email]>
hell everybody,

id don't get the point with spodmacros relations.

i use to to it with regular spods .. but i got lost with the macros ones.

the doc says :

class User extends sys.db.Object {
     public var id : SId;
     // ....
}
class Group extends sys.db.Object {
   public var id : SId;
   // ...
}

@:id(gid,uid)
class UserGroup extends sys.db.Object {
     @:relation(uid) public var user : User;
     @:relation(gid) public var group : Group;
}

ok ..

now i just gave a try ..

my spod bebe 
@:table ('bebe')
@:id(id)
class Bebe extends sys.db.Object , implements Spodable{
public var id : SId;
    public var titre : SString<255>;
@:relation(rid) public var rel:Papa;
//tried @:relation(rid) public var rel(dynamic,dynamic):Papa; //causes error invalid relation field type
}

and another spod

@:table ('papa') @:id(id) class Papa extends sys.db.Object , implements Spodable{ public var id : SId; public var titre : SString<255>; @:skip public var bebeliste:List<Bebe>;

// will use it to populate bebeliste with make() and unmake() public static var manager:Manager<Papa>= new Manager<Papa>(Papa);  }



in my Main class:

public function new()
{
var db = new Database(); /// set the connection
var b=new vo.Bebe();
b.titre="girl";
var papa=vo.Papa.manager.get(1); //retrieve existing Papa entry
trace(papa.titre);
b.rel=papa; // causes error invalid call
b.insert();

}

if someone could explain or correct my code ... i would be pleased to modify the doc to make it more explicit .

Thanks

postite

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

postite
thanks blue112

ok but there is no "fucking" relation in that way ... 



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

Nicolas Cannasse
In reply to this post by postite
Le 29/09/2011 09:47, david a écrit :
[..]

> in my Main class:
>
> public function new()
> {
> var db = new Database(); /// set the connection
> var b=new vo.Bebe();
> b.titre="girl";
> var papa=vo.Papa.manager.get(1); //retrieve existing Papa entry
> trace(papa.titre);
> b.rel=papa; // causes error invalid call

On which platform do you get the invalid call ? PHP or Neko ?

Best,
Nicolas


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

Nicolas Cannasse
In reply to this post by Blue Sans douze
Le 29/09/2011 09:59, Blue Sans douze a écrit :
> b.rel=papa; // causes error invalid call
> It's incorrect.
>
> What you can do is modify the Bebe class and add that :
> public var rid:Int;
>
> Then :
> b.rid = papa.id <http://papa.id>;

SPOD allows to directly set the relation value, and will automatically
modify the key.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

Blue Sans douze
Oh, I didn't know that !

Great feature.
Blue112

2011/9/29 Nicolas Cannasse <[hidden email]>
Le 29/09/2011 09:59, Blue Sans douze a écrit :
b.rel=papa; // causes error invalid call
It's incorrect.

What you can do is modify the Bebe class and add that :
public var rid:Int;

Then :
b.rid = papa.id <http://papa.id>;

SPOD allows to directly set the relation value, and will automatically modify the key.

Nicolas


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

postite
In reply to this post by Nicolas Cannasse
thx Nicolas 
but how ?



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

Nicolas Cannasse
In reply to this post by Nicolas Cannasse
Le 29/09/2011 10:29, Nicolas Cannasse a écrit :

> Le 29/09/2011 09:47, david a écrit :
> [..]
>> in my Main class:
>>
>> public function new()
>> {
>> var db = new Database(); /// set the connection
>> var b=new vo.Bebe();
>> b.titre="girl";
>> var papa=vo.Papa.manager.get(1); //retrieve existing Papa entry
>> trace(papa.titre);
>> b.rel=papa; // causes error invalid call
>
> On which platform do you get the invalid call ? PHP or Neko ?

Oh. Just make sure you call sys.db.Manager.initialize() BTW.

Nicolas




--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

postite
In reply to this post by postite
on Neko for the moment ...
but the target is PHP later.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: spod macros relations

postite
In reply to this post by Nicolas Cannasse
Yeeeeessss !
Thanks nico...
i 've just forgotten the initialize stuff.

everything's ok now ...

thanks


--
haXe - an open source web programming language
http://haxe.org