I have this relationship in MySQL:
My problem is when i want to select menu items, from menu table, depends on user rules in rule table with specific user id, error comes: Model 'Menu' could not be loaded
This is my code:
class Users extends Model
{
public $id,$name,$username,$password,$active;
public function initialize()
{
$this->setSource('bee_sysuser');
$this->hasMany('id','Rules','id_user',['alias'=>'user_rules']);
$this->hasManyToMany(
'id',
'Rules',
'id_user',
'id_menu',
'Menu',
'id',
array('alias' => 'menus')
);
}
}
class Menu extends Model
{
public $id,$name,$parent,$lft,$rgt,$link,$sort,$level,$islink,$disabled,$id_admin,$admin_only;
public function initialize()
{
$this->setSource('bee_menu');
$this->hasMany('id','Rules','id_model',['alias'=>'user_rules']);
$this->hasManyToMany(
'id',
'Rules',
'id_menu',
'id_user',
'User',
'id',
array('alias' => 'users')
);
}
}
class Rules extends Model
{
public $id_user,$id_menu,$type;
public function initialize()
{
$this->setSource('bee_settings_rules');
$this->belongsTo('id_user', 'Users', 'id',
array('alias' => 'users'));
$this->belongsTo('id_menu', 'Menu', 'id',
array('alias' => 'menus'));
}
}
There im trying to call it:
$user = Users::findFirst(
[
'id = :id:', 'bind' => ['id' => 1]
]
);
\Tracy\Debugger::barDump($user->menus);
$user is exists with data from Users model, but im not able to access to Menu model, as i mentioned before.
Any help would be appreciate
Thanks, and sorry about my english.