How to crate where condition, when you need to match 2 columns ?

I am trying to write this query using AR:

AND (document.datum_izvora = document_content.editDate)

I have tried this:

$this->_query->andFilterWhere(['document.datum_izvora => document_content.editDate'])

but it is not doing what I want since it is quoting second parameter as value.

My colleague has tried this dirty solution, and I would like to know if there is any better ?

$this->_query->andFilterWhere(['and', 'document.datum_izvora = document_content.editDate', '1=1']);

Use "andWhere" in place of "andFilterWhere" here, because the latter "Adds an additional WHERE condition to the existing one but ignores empty operands."

A string as the condition might be the simplest solution.

$this->_query->andWhere('document.datum_izvora = document_content.editDate')

Thank you. I have one question though. What "ignores empty operands" really means ? Yii will not execute that condition if value that is passed is empty ?


This is not a precise explanation, but roughly speaking,

$query->andFilterWhere(['some_column' => $this->some_column]);

can be considered as

if ($this->some_column != "") {

    $query->andWhere(['some_column' => $this->some_column]);


Please check the source code of yii\db\QueryTrait::andFilterWhere() and yii\db\QueryTrait::filterCondition()