atk4\data\Model::action PHP Method

action() public method

Execute action.
public action ( string $mode, array $args = [] ) : atk4\dsql\Query
$mode string
$args array
return atk4\dsql\Query
    public function action($mode, $args = [])
    {
        if (!$this->persistence) {
            throw new Exception(['action() requires model to be associated with db']);
        }
        return $this->persistence->action($this, $mode, $args);
    }

Usage Example

Example #1
0
 public function testExpressions()
 {
     $a = ['user' => [1 => ['id' => 1, 'name' => 'John', 'surname' => 'Smith', 'cached_name' => 'John Smith'], 2 => ['id' => 2, 'name' => 'Sue', 'surname' => 'Sue', 'cached_name' => 'ERROR']]];
     $this->setDB($a);
     $db = new Persistence_SQL($this->db->connection);
     $m = new Model($db, 'user');
     $m->addFields(['name', 'surname', 'cached_name']);
     $m->addExpression('full_name', '[name] || " " || [surname]');
     $m->addCondition($m->expr('[full_name] != [cached_name]'));
     $this->assertEquals('select `id`,`name`,`surname`,`cached_name`,(`name` || " " || `surname`) `full_name` from `user` where (`name` || " " || `surname`) != `cached_name`', $m->action('select')->render());
     $m->tryLoad(1);
     $this->assertEquals(null, $m['name']);
     $m->tryLoad(2);
     $this->assertEquals('Sue', $m['name']);
 }
All Usage Examples Of atk4\data\Model::action