gpt4 book ai didi

mysql - Cakephp 查询生成器 : update rows with an identical field as selected one

转载 作者:行者123 更新时间:2023-11-29 06:58:06 28 4
gpt4 key购买 nike

我的应用程序的目标是通过特许经营安排帖子到其特许经营。总部安排在特定日期和时间发布帖子,并附有文字和潜在图像。它使用数据库中每个特许经营商的所有必要信息创建帖子(id、franchise_id、user_id、文本、图像、网络、post_id)

post_id 包含一个与每一行相同的 ID,除了特许经营 ID 之外,该 ID 完全相同。

当我添加帖子时,效果很好。但是在编辑时,由于它获取了帖子的 ID,因此它只会编辑与该 id 匹配的帖子。当它是特许经营时,这很好,然后它将把 post_id 更改为自定义值,并且将独立于其他值。

但是当总部( super 管理员)登录时,我希望他编辑所有与 post_id 所选内容匹配的内容。

查询构建器不是我习惯的东西,有时我考虑过将其放弃以用于标准 SQL,但如果它存在,那也是有原因的,所以我希望您能帮助我使用 Cakephp 的查询构建器解决这个问题。

public function edit($id = null){

$event = $this->Events->get($id);

if ($this->request->is(['post', 'put'])) {
$event = $this->Events->patchEntity($event, $this->request->data,['associated' => ['Networks'], ]);
if($isuper == 'true'){//if logged in user is superadmin

}else{
$event->user_id = $this->Auth->user('id');
}


if ($this->Events->save($event)) {



$this->Flash->success(__('your post has been updated'));
return $this->redirect(
[
'action' => 'index',
date('Y', $event->date->getTimestamp()),
date('m', $event->date->getTimestamp()),
$event->company_id
]
);
}
$this->Flash->error(__('unable to update your post'));
}
$this->set('event', $event);
$this->layout = 'ajax';
}

最佳答案

您可以尝试使用 updateAll 进行批量更新

类似于:

$this->Events->updateAll(
['field' => true], // whatever fields you are updating
['post_id' => 'some_id'] // the selected post_id
);

关于mysql - Cakephp 查询生成器 : update rows with an identical field as selected one,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44783690/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com