Beispiel #1
0
 public function testUpdate()
 {
     $data = [['id' => 1, 'name' => 'foo'], ['id' => 2, 'name' => 'bar'], ['id' => 3, 'name' => 'foobar']];
     // Update all
     $source = new ArrayDataSource($data);
     $selection = new UpdateSelectionBuilder($source);
     $selection->set('name', 'baz')->update();
     foreach ($source->getData() as $record) {
         $this->assertEquals('baz', $record['name']);
     }
     // Update using expression
     $selection = new UpdateSelectionBuilder($source);
     $selection->set('name', E::e('id'))->update();
     foreach ($source->getData() as $record) {
         $this->assertEquals($record['id'], $record['name']);
     }
 }
Beispiel #2
0
 /**
  * Assign value to field.
  * If `$field` is an associative array, then multiple
  * fields are assigned.
  *
  * @param (mixed|Expression)[]|mixed|Expression $field
  *            Field name or associative array of update data (see
  *            {@see UpdateSelection::getData} for format.
  * @param mixed|Expression $value
  *            Field value. May be an expression.
  * @return static
  */
 public function set($field, $value = null)
 {
     $selection = new UpdateSelectionBuilder($this->getSource());
     return $selection->set($field, $value);
 }