我想在模型hasMany槽中保存2个以上的数据。但这不是保存。
$data[] = array('User' => array('id' => 5), 'Solicitation' => array('id' => $this->Solicitation->id));
$data[] = array('User' => array('id' => 6), 'Solicitation' => array('id' => $this->Solicitation->id));
debug($data);
$this->SolicitationUser->saveAll($data);
debug($data)
array(
(int) 0 => array(
'User' => array(
'id' => (int) 5
),
'Solicitation' => array(
'id' => '70'
)
),
(int) 1 => array(
'User' => array(
'id' => (int) 6
),
'Solicitation' => array(
'id' => '70'
)
)
)
答案 0 :(得分:1)
很难说出你要追求的是什么,因为没有什么描述,但我想你更希望它更像这样在你的HasMany通过表中保存两行:
array(
(int) 0 => array(
'user_id' => (int) 5
'solicitation_id' => '70'
),
(int) 1 => array(
'user_id' => (int) 6
'solicitation_id' => '70'
)
)