I use CakeDC plugin. I want to link another player_heroes table to the users table. added field to profile edit
$this->Form->select('PlayerHeroes.hero', $heroes, ['multiple' => true, 'id'=>'fav-hero-select' ]); added controller to action
$entity = $table->patchEntity($entity, $this->request->getData(), ['associated'=>['PlayerHeroes']]); if ($table->save($entity)) { $this->Flash->success(__d('CakeDC/Users', 'The {0} has been saved', $singular));} in Entity\Users.php registered hasMany ( uid field in the player_heroes table)
public function initialize(array $config) { parent::initialize($config); $this->setTable('users'); $this->setDisplayField('username'); $this->setPrimaryKey('id'); $this->addBehavior('Timestamp'); $this->addBehavior('CakeDC/Users.Register'); $this->addBehavior('CakeDC/Users.Password'); $this->addBehavior('CakeDC/Users.AuthFinder'); $this->hasMany('PlayerHeroes', [ 'foreignKey' => 'uid']); } After saving the profile, the users table is updated, and player_heroes empty. Maybe it's in the ways? Users is in vendor/cakedc/src/ , and PlayerHeroes at the root of app/src/ . No mistakes knocks out
belongsToManyconnection and an intermediate table to store it. If this connection is itself represented as an entity, then for this there is athroughoption in the config. - teranselect("Users.PlayersHeroes.hero"), although for selects it is usually written._idsif you have checkboxes for your choice. In general, it’s not quite clear to me what and how you want to link and edit at all - teranassociatedpatchprescribed when they want to change the data themselves. if you only need to keep the connection, it is not necessary. So make it clear what you are trying to do at all - teranbelongsToManylink and select for_ids. Option 2) you want to directly create characters for the user. But then you need not selects with checkboxes, but input for entering the names of heroes, and then, yes, you need theassociatedpatchEntity. I think you need option 1 - with many to many connections. Each user can select several heroes of the common list, and a hero can be selected by several users. - teran