我有這樣的:更新相關表中的蛋糕
$this->request->data['Person']['person_id'] = $this->Session->read('insertedPersonID');
$savedPerson = $this->Person->saveAll($this->request->data, array('validate'=>'first'));
該更新被選擇的人排精然而像PersonColor和PersonParts其相關的表沒有更新,而不是插入新行。
我想蛋糕自動更新相關的表,以及只要主表的id,這將是對其他兩個表的外鍵,因爲這樣做提供:
$savedPerson = $this->Person->saveAll($this->request->data, array('validate'=>'first'));
插入到人表和其他兩個相關的兩個表罰款。
如何更新其他兩張表?
編輯: 對於模型的關係:
角色模型:
public $hasMany = array(
'PersonParts' => array(
'className' => 'Part',
'foreignKey' => 'part_person_id'
),
'PersonColors' => array(
'className' => 'Color',
'foreignKey' => 'color_person_id'
)
);
部分型號:
public $belongsTo = array(
'PartPerson' => array(
'className' => 'Person',
'foreignKey' => 'part_person_id'
)
);
顏色型號:
public $belongsTo = array(
'ColorPerson' => array(
'className' => 'Person',
'foreignKey' => 'color_person_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
編輯2
的$這 - 的var_dump>請求 - >數據
array(3){
["Person"]=>array(4){
["person_user_id"]=>string(1)"3"
["person_name"]=>string(9)"Britney"
["person_category_id"]=>string(2)"16"
["visibility"]=>string(1)"1"
["person_id"]=>string(1)"71"
}
["PersonParts"]=>array(1){
[0]=>array(3){
["part_name"]=>string(4)"hands"
["quantity"]=>string(1)"2"
["part_part_type_id"]=>string(1)"1"
}
}
["PersonColors"]=>array(2){
[0]=>array(4){
["color_name"]=>string(3)"blue"
["test_field1"]=>string(1)"8"
["test_field2"]=>string(1)"9"
["position"]=>int(1)
}
[1]=>array(2){
["color_name"]=>string(5)"red"
["position"]=>int(2)
}
}
}
注意:此的var_dump僅示出[ 「爲person_id」] =>串(1) 「71」 以下的人數組作爲添加的字段,使蛋糕做更新,而不是插入... person_id沒有顯示在這裏的PersonParts和PersonColors,因爲它不是這樣工作的。我應該通過什麼或者我應該如何對其他2個相關表格進行更新?
可以粘貼與Person,Personcolor和PersonParts模型中的關係有關的代碼嗎? – cornelb
@cornelb好吧,我在「編輯」後發佈了關於問題的模型關係 – Leah
您可以在保存之前發佈$ this-> request-> data的var_dump嗎? –