updateAll – expression

Aktualizuje wiele rekordów

function publishAllUnpublished()
{
  $this->updateAll(
    [ // fields
     'published'    => true,
     'publish_date' => FrozenTime::now()
    ],
    [ // conditions
     'published' => false
    ]
  );
}

Użycie wyrażenia

use Cake\Database\Expression\QueryExpression;
...
function incrementCounters()
{
  $expr = new QueryExpression('view_count = view_count +1');
  $this->updateAll([ $expr], [ 'published' => true]);
}
$this->query()
  ->update()
  ->set([ 'published' => true ])
  ->where([ 'published' => false ])
  ->execute();

Dodaj komentarz