【发布时间】:2016-10-18 14:18:21
【问题描述】:
我有一个表“主题”,它与模型中的 hasMany 链接到“帖子”。
我不知道如何同时更新这两个表。
这是我的 $this->request->data
Array
(
[Topic] => Array
(
[id] => 1
[topic_title] => This is my topic
)
[Post] => Array
(
[1] => Array
(
[id] => 1
[title] => Blah
[message] => My message
)
[2] => Array
(
[id] => 2
[title] => Second Blah
[message] => Second My message
)
)
)
我试过这样做:
$this->Topic->save($this->request->data);
$this->loadmodel('Post');
$this->Post->updateAll($this->request->data, array('Post.topic_id' => $id));
这显然是错误的方法,但是我努力寻找一种好的方法。
【问题讨论】:
标签: cakephp cakephp-2.0 cakephp-2.3 cakephp-2.1