You need to register custom function (should be added in doc or faq somewhere), example for IF(condition, value_if_true, value_if_false) :
<?php
use Phalcon\Db\Dialect\MySQL as SqlDialect,
Phalcon\Db\Adapter\Pdo\Mysql;
$di->set('db', function () use ($config) {
$dialect = new SqlDialect();
$dialect->registerCustomFunction('IF', function($dialect, $expression) {
return sprintf(
'IF('.$dialect->getSqlExpression($expression['arguments'][0]).', %d, %d)',
$dialect->getSqlExpression($expression['arguments'][1]),
$dialect->getSqlExpression($expression['arguments'][2])
);
}
);
return new Mysql([
'host' => $config[ENV]->database->host,
'username' => $config[ENV]->database->username,
'password' => $config[ENV]->database->password,
'dbname' => $config[ENV]->database->dbname,
'charset' => $config[ENV]->database->charset,
'dialectClass'=>$dialect
]);
});
$robots = Robot::find([
'columns'=>('*, IF(id < 10, 1, 0) as isValid')
]);