我试图在 2 个模型之间建立多对多关系:Users_Role 和 Users_Right
class Model_Users_Role extends ORM{
protected $_has_many = array(
'rights' => array(
'model' => 'users_right',
'through' => 'users_roles_rights',
),
);
}
class Model_Users_Right extends ORM{
protected $_has_many = array(
'roles' => array(
'model' => 'users_role',
'through' => 'users_roles_rights',
),
);
}
我正在尝试这样做:
$role = ORM::factory('users_role', 1);
$right = ORM::factory('users_right', 1);
$right->add('roles', $role);
错误:
Database_Exception [ 1054 ]: Unknown column 'role_id' in 'field list' [ INSERT INTO `users_roles_rights` (`users_right_id`, `role_id`) VALUES ('1', '1') ]
我试图在另一边做到这一点:
$role = ORM::factory('users_role', 1);
$right = ORM::factory('users_right', 1);
$role->add('rights', $right);
新错误:
Database_Exception [ 1054 ]: Unknown column 'right_id' in 'field list' [ INSERT INTO `users_roles_rights` (`users_role_id`, `right_id`) VALUES ('1', '1') ]
我希望 ORM 在数据透视表中使用users_role_id
和users_right_id
字段名称,但它使用了错误的远键名称?我在哪里犯了错误?