HaxeFoundation / HaxeFoundation/record-macros
lock behaviour
- Dominant language
- Haxe
- Stars
- 48
- Forks
- 25
- PR merge metrics
- No merged PRs in 30d
Description
Hej Jonas,
I hope you're in a good mood because I've another headacke for you...
I don't know if it's really a bug or maybe just a behaviour that should be more explicitly described, I'll try to explain with the minimalest example that I could do.
Let's say we have that :
This C class is just used to make the bug rise : As noted, this `get_as` function must be called (I think it's because of the A references...)
```haxe
class C extends sys.db.Object {
var id : SId;
@:skip
public var as (get,null) : List;
public function new() {
super();
}
function get_as(){
return A.manager.search( $c == this ); // <--- If not called, all is ok even if lock == false
}
}
```
This A class has a special `hxSerialize` and `hxUnserialize` function to get a custom serialization, which consist of having a field called `xfields` that will just have the fields to serialize.
And in `get_bs()` I do a call to upper class in order to rise the bug
```haxe
class A extends sys.db.Object{
@:skip
public var xfields (get,null): Array;
var id : SId;
@:relation( cID )
public var c : C;
@:skip
public var bs (get,null) : Array;
public function new() {
super();
}
function get_bs(){
var tmp = c.as; // <------- to get the call, then the bug
return bs = Lambda.array( B.manager.search( $a == this ) );
}
//
function get_xfields(){
if( xfields == null ) xfields = [ "id", "c" ];
return xfields;
}
@:keep
public function hxSerialize( s : haxe.Serializer ) {
s.serialize( xfields.join( "," ) );
for ( f in xfields ) {
s.serialize( Reflect.getProperty( this, f ) );
}
}
@:keep
public function hxUnserialize( u : haxe.Unserializer ) {
var sxfields : String = u.unserialize();
xfields = sxfields.split( "," );
for ( f in xfields ) {
Reflect.setProperty( this, f, u.unserialize() );
}
}
}
```
Nothing special here...
```haxe
class B extends sys.db.Object {
var id : SId;
@:relation( aID )
public var a : A;
public function new() {
super();
}
}
```
And now the Main class (I'm sorry I tried your quick statements to create the table without success so I've done it using INSERT...:
```haxe
class Main {
static function main(){
haxe.Serializer.USE_CACHE = true;
sys.db.Manager.cnx = sys.db.Sqlite.open(":memory:");
sys.db.Manager.cnx.request("CREATE TABLE A AS SELECT 1 id, 1 cID");
sys.db.Manager.cnx.request("INSERT INTO `A` (`id`, `cID`) VALUES (2, 1), (3, 1)");
sys.db.Manager.cnx.request("CREATE TABLE B AS SELECT 1 id, 1 aID");
sys.db.Manager.cnx.request("CREATE TABLE C AS SELECT 1 id");
var list = Lambda.array( A.manager.unsafeObjects( "SELECT * FROM A WHERE cID = 1", false ) ); // <---- If lock == false then bug
for( o in list ){
o.xfields.push( "bs" );
trace( o.xfields );
}
var ser = Serializer.run( list );
var userList : Array = Unserializer.run( ser );
for( o in userList ){
trace( o.xfields );
}
}
}
```
I'm sorry for this "swamp" but I would like to understand what is going on here.
As you'll see in the traces, if `lock` is true, then the unserialized objects have all their `xfields` filled, but if `lock` is false, only one of the unserialized objects will have the `bs` string added to its `xfields`.
Then it's interesting to note that if there is no that `var tmp = c.as; // <------- to get the call, then the bug` in the A class, all is working fine even if `lock` is false.
If you could explain me what is going on, if it's a normal behaviour or if it's a bug please ?
Thanks Jonas !
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.