我试图从父控制器获取所有子数据以对所有子数据进行编辑,并且我已经使这个功能得到它们,
public function edit($id = 'Contractors.id') {
$contractor = $this->Contractors->get($id, [
'contain' => ["ContractorsAttachments"]
]);
$ContractorsAttachments = $this->Contractors->ContractorsAttachments->find()->where(['ContractorsAttachments.contractor_id', $id])->all();
if ($this->request->is(['patch', 'post', 'put'])) {
$array_dif = array();
if (!empty($this->request->data['contractors_attachments'])) {
foreach ($this->request->data['contractors_attachments'] as $attach) {
if (isset($attach['id']))
$array_dif[] = $attach['id'];
}
}
$ContractorsAttachments = $this->Contractors->patchEntity($ContractorsAttachments, $this->request->data,[
'associated' => ['ContractorsAttachments']
]);
if ($this->Contractors->save($ContractorsAttachments)) {
$this->Flash->success(__('The contractor has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The contractor could not be saved. Please, try again.'));
}
}
$attachments = $this->Contractors->ContractorsAttachments->find('list', ['limit' => 200]);
但它回来了每个父ID的子表中的所有数据! ,我只需要那个条件就可以回来了 where([' ContractorsAttachments.contractor_id',Contractors.id])
那么,我的代码出了什么问题!