Php 在另一个控制器中向另一个数据库表添加值是在添加新项
将数据从chats controller保存到聊天模型后,我想将此聊天项目的最后一个id添加到另一个名为issues的数据库表中。我从ChatsController执行此操作:Php 在另一个控制器中向另一个数据库表添加值是在添加新项,php,mysql,cakephp,Php,Mysql,Cakephp,将数据从chats controller保存到聊天模型后,我想将此聊天项目的最后一个id添加到另一个名为issues的数据库表中。我从ChatsController执行此操作: // Get last inserted id from Chat $lastid = $this->Chat->getLastInsertId(); // Set the issue id to be updated $this->Cha
// Get last inserted id from Chat
$lastid = $this->Chat->getLastInsertId();
// Set the issue id to be updated
$this->Chat->Issue->id = $issueid;
// Update Issue table
$this->Chat->Issue->saveField('chat_id', $lastid);
其中,我要使用id$issueid更新问题数据库项,并将$lastid添加到字段Issue.chat_id。$issueid之前已设置且存在,我假设$lastid也已设置
在问题模型和聊天模型中,模型都属于另一个
在问题数据库表中插入新行而不是更新正确的行,这有什么错?是否确实将
$issueid
设置为问题
表中已存在的id?是的,使用issueid:public function view_issue($issueid){若要将该项添加到聊天数据库表中,请将其设置为正确。请尝试将保存切换为使用save()方法,这可能表明这是使用saveField()方法的问题还是$issueid的值的问题