In my AcosTable.php I have
$this->hasMany('ChildAcos', [
'alias' => 'ChildAcos',
'className' => 'Acos',
'foreignKey' => 'parent_id'
]);
I need table name(className property) in appController. In my appController I have
$associations = $this->{$this->modelClass}->associations();
foreach ($associations->type('HasMany') as $item) {
$options['name'] = $item->name(); //ChildAcos
$options['foreignKey'] = $item->foreignKey(); //parent_id
//$options['className'] = $item->?(); //Acos
$hasMany[] = $options;
}
How can I retrieve className?
As opposed to all the other association options, there seems to be no way to get hold of the value of Association::$_className
, you may want to report this over at GitHub, I think it wouldn't hurt to make this accessible too (at least readable).
For now it seems that all you can do is figure it from the target tables full classname, something like:
$fqn = get_class($item->target());
$parts = namespaceSplit($fqn);
$className = substr(end($parts), 0, -5);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments