Welcome Guest, Not a member yet? Register   Sign In
Using updateBatch correctly
#1

I'm about to add this to my controller:

PHP Code:
foreach ($orders as $order) {
  $data['order_id'] = $order['id'];
  $data['status'] = $order['status'];
  $orderModel->save($data);


But I'm always concerned about this repeated calls to the DB ending on a syncing error or performance issue. Would this be the right moment to start using updateBatch?  If so, is this the way the controller would look like?

PHP Code:
foreach ($orders as $order) {
  $data[] = array(
  'order_id' => $order['id'],
  'status'=> $order['status']
  );
}
$result $orderModel->updateBatch($data,'order_id'); 

This is CI4 and Orders Model has no functions, only $allowedFields and $primaryKey defined.
Reply
#2

Looks okay to me.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB