Как перевести запрос mysql
select * from crmLogBalance
inner join
(select id as tabId, diff as positive, 0 as negative from crmLogBalance where diff>=0
union
select id as tabId, 0 as positive, diff as negative from crmLogBalance where diff<0) as tab
on tabId=id
на
try {
$with = ['Partner'];
$subQueryA = CRM\LogBalance::query()->select("id", "0 as positive", "diff as negative")->where('diff', '<', 0);
$subQueryB = CRM\LogBalance::query()->select("id", "diff as positive", "0 as negative")->where('diff', '>=', 0)->union($subQueryA); //здесь дебаг останавливается. Выдает экран "Template cache file" . А подробности ошибки не вижу.
$qery=$query->with($with)->joinSub($subQueryB, 'posNeg', function (JoinClause $join) {
$join->on(CRM\LogBalance::db().'.id', '=', 'posNeg.id');})->get();
} catch (\Exception $exception) {
echo $exception;
}
есмли поменять строчки местами
subQueryB = CRM\LogBalance::query()->select("id", "diff as positive", "0 as negative")->where('diff', '>=', 0); //то это выполняется
$subQueryA = CRM\LogBalance::query()->select("id", "0 as positive", "diff as negative")->where('diff', '<', 0); //а это нет, выдает ошибку, какую не знаю.