CakePHP 3 示例更新到 SaveMany 而不是插入到 SaveMany

CakePHP 3 Example Update to SaveMany not Insert to SaveMany

我更新多条记录时遇到问题。它对我不起作用,在 CakePHP 文档中没有关于更新的内容,只是提供多个高位寄存器,但没有更新现有字段。

我的示例错误,未更新;-(

$ids = [101,123];

$data_update = [
  [
   'id'=>101,
   'licensees_id'=>'10',
  ],
  [
   'id'=>123,
   'licensees_id'=>'10',
  ],
];

// Get all users
    $usersEntity = $this->Users->find('all',[
           'fields'=>[
               'id',
               'licensees_id',
           ],
            'conditions'=>[
                'id IN'=>$ids
            ]
        ]);
        $usersEntity = $this->Users->patchEntity($usersEntity, $data_update); //<= Error parant
//        exit(debug($usersEntity));
        $result = $this->Users->saveMany($usersEntity);

解决我在 CakePHP 3 中的问题以 saveMany(),

->patchEntity()是一行"Entity"更新,for save()

->patchEntities() 是多行 "Entities" 更新 saveMany()

;-)

// Change Line
$usersEntity = $this->Users->patchEntity($usersEntity, $data_update);
// For
$usersEntity = $this->Users->patchEntities($usersEntity, $users_data);