Jakiro
(Out)
March 13, 2016, 9:06pm
1
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 ;[
softark
(Softark)
March 14, 2016, 11:06am
2
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.
Jakiro
(Out)
March 14, 2016, 2:02pm
3
softark:
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.
https://github.com/yiisoft/yii2/blob/master/framework/db/ActiveRelationTrait.php
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
softark
(Softark)
March 14, 2016, 3:32pm
4
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();
}