Expression in relation

Hello everyone!

How can i do an Expression in relation?


public function getInterval()

  {

    return $this->hasMany(Notifies::className(), ['DATE(date_add)' => 'DATE(date_add)']);

  } 

It does not work


public function getInterval()

  {

    return $this->hasMany(Notifies::className(), [new \yii\db\Expression('DATE(date_add)') => new \yii\db\Expression('DATE(date_add)')]);

  } 

It too does’t work, illegal type error ;[

I don’t understand your intention. What sql do you want to generate with this?

Would you please explain your table definitions?

[EDIT]

As far as I understand, using expressions for relationnal definition is not supported.

ActiveQuery::$link must be an array in which both the keys and the values are column names without prefix.

I have https://yadi.sk/d/LhBJn7KCqAiR4 structure

I grouping all rows by date_add field AND getting one row 2016-03-14

But now, i want to get all recount in 14 march throw relation from grouping row

I see. So you have to convert datetime to date using date() function.

I’m not sure whether it’s possible or not to construct a relation that you want with some tricky code.

IMO, it’s better to consider simpler way to get your things done. I would write something like the following to get an array of Notifies objects:




public function getIntervals()

{

    return Notifies::find()

        ->where('date(date_add) = date(:date_add)', [':date_add' => $this->date_add])

        ->all();

}