例如,如果我们有:
Array
(
[User] => Array
(
[id] => 121
[name] => Gwoo the Kungwoo
[created] => 2007-05-01 10:31:01
)
[Comment] => Array
(
[0] => Array
(
[id] => 123
[user_id] => 121
[title] => On Gwoo the Kungwoo
[body] => The Kungwooness is not so Gwooish
[created] => 2006-05-01 10:31:01
)
[1] => Array
(
[id] => 124
[user_id] => 121
[title] => More on Gwoo
[body] => But what of the 'Nut?
[created] => 2006-05-01 10:41:01
)
)
)
来自http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
如果使用一个表单提交所有这些数据,我们应该如何从用户控制器对Comment表进行更新?
这与我的问题在某种程度上相同:updating related tables in cake我遗憾地得不到正确答案。有人可以告诉我这是如何工作的吗?
答案 0 :(得分:0)
使用$ this-> User-> saveAssociated($ yourArray);
它会相应地保存所有数据
答案 1 :(得分:0)
$this->User->saveAll($data)