やりたいこと
CakePHPのQueryBuilderで、DBのカラム同士を比較したい
例えば、created_atカラムとupdated_atカラムを比較する、など
だめな例
public function check()
{
return $this->query()
->where([
'created_at <' => 'updated_at',
])
->toArray();
}
良さげな例
public function check()
{
return $this->query()
->where([
'created_at <' => $this->query()->identifier('updated_at'),
])
->toArray();
}
updated_atの部分を$this->query()->identifier('updated_at')に変更します。
($this->query()->identifier('カラム名'))