您可以用这种方式保存关联数据。
您的数据数组应该是这种格式。
$data = array(
"command"=> "whoami",
"description"=> "SOMETHING",
"public"> false,
"tags": [
array("name" => "TEST1"),
array("name"=> "TEST2")
]
)
$patchedEntity= $this->Commands->patchEntity($saveData,$data,['associated' => ['Tags']]);
$result = $this->Commands->save($patchedEntity);
在命令表中定义关系应该是这样的。
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('commands');
$this->hasMany('Tags', [
'foreignKey' => 'command_id'
]);
}
public function initialize(array $config)
{
parent::initialize($config);
$this->setTable('tags');
$this->belongsTo('Commands', [
'foreignKey' => 'command_id'
]);
}