im trying to do a simple addCase() with literal option but it nevers create the correct SQL or the ELSE statement:
//https://book.cakephp.org/3.0/en/orm/query-builder.html#case-statements
//Any time there are fewer case conditions than values, addCase will automatically produce an if … then … else statement
//with 2 cases and 3 matching conditions
$data = $query->newExpr()
->addCase(
[
$query->newExpr()->add(['field1' => '']),
$query->newExpr()->isNull('field1')
],
[
'field2' => 'literal',
'field2' => 'literal',
'field1' => 'literal',
],
['string', 'string', 'string']
);
return SQL: (CASE WHEN field1 = ‘’ THEN field2 WHEN (field1) IS NULL THEN field1 END)
expected SQL: (CASE WHEN field1 = ‘’ THEN field2 WHEN (field1) IS NULL THEN field2 ELSE field1 END)
//with 1 case and 2 matching conditions
$data = $query->newExpr()
->addCase(
[
$query->newExpr()->add(['field1' => ''])
],
['field2' => 'literal', 'field1' => 'literal'],
['string', 'string']
);
return SQL: (CASE WHEN field1 = ‘’ THEN field2 ELSE ‘literal’ END )
expected SQL: (CASE WHEN field1 = ‘’ THEN field2 ELSE field1 END )