What “type” do I specify in addCase to return a column?

末鹿安然 提交于 2019-12-02 04:06:46

By default the values passed to the second argument of QueryExpression::addCase() are being treated as to be converted to literal values, not as identifiers. If you need the latter, then you should use an expression, an IdentifierExpression.

use Cake\Database\Expression\IdentifierExpression;

// ...

$team_id = $query->newExpr()->addCase(
    [
        $query->newExpr()->eq('Games.status', 'home_default')
    ],
    [
        new IdentifierExpression('Games.home_team_id'),
        new IdentifierExpression('Games.away_team_id')
    ]
);

Also ditch the third argument in this case, you don't want the values to be string literals (for expressions the types would be ignored anyways).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!