record-macros
record-macros copied to clipboard
SEnum field as table @id
Following is an old issue from SPOD, that is still present in this library. See https://github.com/HaxeFoundation/haxe/issues/4144
Say I use an simple record :
import sys.db.Types;
import sys.db.Manager;
@:id( lang )
class Locale extends sys.db.Object
{
public static var manager = new Manager<Locale>(Locale);
public var lang:SEnum<LocaleString>;
public var locale:SString<5>;
}
enum LocaleString
{
fr;
en;
/*TODO es; de;*/
}
While compiling to php, no error happens, but at runtime, I get this error :
uncaught exception: Missing key lang
in file: /project/02-cms/out/lib/sys/db/Manager.class.php line 701
#0 /project/02-cms/out/lib/sys/db/Manager.class.php(727): sys_db_Manager->makeCacheKey(Object(model_db_Locale))
#1 /project/02-cms/out/lib/sys/db/Manager.class.php(448): sys_db_Manager->addToCache(Object(model_db_Locale))
#2 /project/02-cms/out/lib/sys/db/Manager.class.php(531): sys_db_Manager->cacheObject(Object(_hx_anonymous), true)
#3 /project/02-cms/out/lib/controller/command/CreatePageFromTemplate.class.php(23): sys_db_Manager->unsafeObjects('SELECT * FROM L...', true)
#4 /project/02-cms/out/lib/controller/command/CreateIndexPage.class.php(16): controller_command_CreatePageFromTemplate->init('LVS, des expert...')
#5 /project/02-cms/out/lib/controller/Router.class.php(170): controller_command_CreateIndexPage->__construct(Object(model_db_LocaleString))
#6 /project/02-cms/out/lib/controller/Router.class.php(156): controller_Router->createPageFromURL(Object(model_db_LocaleString), '', NULL)
#7 /project/02-cms/out/lib/Reflect.class.php(27): controller_Router->doFr('', NULL, NULL)
#8 /project/02-cms/out/lib/haxe/web/Dispatch.class.php(66): Reflect::callMethod(Object(controller_Router), Array, Object(_hx_array))
#9 /project/02-cms/out/lib/Main.class.php(18): haxe_web_Dispatch->runtimeDispatch(Object(_hx_anonymous))
#10 /project/02-cms/out/index.php(11): Main::main()
#11 {main}
Here is the haxe code that produce the trouble :
var changeLocale
= switch( Router.locale )
{
case LocaleString.fr : Locale.manager.select( $lang != LocaleString.fr ).lang;
case LocaleString.en : Locale.manager.select( $lang != LocaleString.en ).lang;
}
After long tests, I narrowed the issue : the lang
field that is used as an @id
.
In order to fix it, change the key to the other field of the table.
Like so :
@:id( locale )
class Locale extends sys.db.Object
{
public static var manager = new Manager<Locale>(Locale);
public var lang:SEnum<LocaleString>;
public var locale:SString<5>;
}
HTH