我有一个Usergroups表,什么是belongsToMany用户。
在我的控制器中
$usergroup = $this->Usergroups->get($id, ['contain' => ['Users']]);
$usergroup->users[0]->_joinData->joined = true;
if ($this->Usergroups->save($usergroup)) {
$this->Flash->success('You have successfully joined');
}
我获得了成功的Flash消息,但我的users_usergroups表中没有为用户设置joined
字段。
有什么猜测?
我在保存的实体看起来像这样。
object(App\Model\Entity\Usergroup) {
'id' => (int) 22,
'name' => 'Test',
'admin_user_id' => (int) 2,
'users' => [
(int) 0 => object(App\Model\Entity\User) {
'id' => (int) 2,
'name' => 'rrd',
'active' => true,
'_joinData' => object(App\Model\Entity\UsersUsergroup) {
'id' => (int) 14,
'user_id' => (int) 2,
'usergroup_id' => (int) 22,
'joined' => true,
'created' => null,
'[new]' => false,
'[accessible]' => [
'id' => true,
'user_id' => true,
'usergroup_id' => true,
'joined' => true
],
'[dirty]' => [
'joined' => true
],
'[original]' => [
'joined' => false
],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'UsersUsergroups'
},
'[new]' => false,
'[accessible]' => [
'name' => true,
'password' => true,
'realname' => true,
'email' => true,
'phone' => true,
'active' => true,
'responsible' => true,
'role' => true,
'resettoken' => true,
'events' => true,
'groups' => true,
'histories' => true,
'notifications' => true,
'locale' => true,
'google_contacts_refresh_token' => true,
'last_login' => true,
'contacts' => true,
'usergroups' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Users'
},
],
'[new]' => false,
'[accessible]' => [
'name' => true,
'admin_user_id' => true,
'users' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Usergroups'
}