Delgus
(Alexey Dolgov)
November 26, 2020, 3:38pm
1
opened 02:14PM - 17 Feb 16 UTC
closed 02:42PM - 11 Apr 16 UTC
Dynamic aliases in relation seem to be missing. Consider this example:
class Customer {
...
public function getOrders()
{
return $this->hasMany( Order::className(), ['customerid'...
Вот это делали когда то, оно еще работает. никто не пользовался?
public function getLengthValue()
{
return $this->hasOne(Value::class, ['product_id' => 'id'])->andOnCondition(['@alias.characteristic_id' => Characteristic::LENGTH_ID]);
}
public function getHighValue()
{
return $this->hasOne(Value::class, ['product_id' => 'id'])->andOnCondition(['@alias.characteristic_id' => Characteristic::HIGH_ID]);
}
Delgus
(Alexey Dolgov)
November 26, 2020, 3:50pm
2
$query->joinWith([
'widthValue' => function (ActiveQuery $q) {
return $q->alias("wv");
},
'lengthValue' => function (ActiveQuery $q) {
return $q->alias("lv");
},
'highValue' => function (ActiveQuery $q) {
return $q->alias("hv");
}
]);
SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘@alias.characteristic_id ’ in ‘on clause’
The SQL being executed was: SELECT MIN(price_new) FROM shop_products
LEFT JOIN shop_values
wv
ON (shop_products
.id
= wv
.product_id
) AND (@alias
.characteristic_id
=15)
Delgus
(Alexey Dolgov)
November 26, 2020, 3:53pm
3
Я делаю это чтоб в один запрос доставать ширину высоту и длину и фильтровать потом
// длина
if ($this->length_from > $this->length_min || $this->length_to < $this->length_max) {
$query->andFilterWhere(['between', 'CONVERT(lv.value,UNSIGNED INTEGER)', $this->length_from, $this->length_to]);
}
// глубина
if ($this->high_from > $this->high_min || $this->high_to < $this->high_max) {
$query->andFilterWhere(['between', 'CONVERT(hv.value,UNSIGNED INTEGER)', $this->high_from, $this->high_to]);
}
Надо самому leftJoin прописывать получается? алиасы не работают?
Delgus
(Alexey Dolgov)
November 26, 2020, 3:58pm
4
все разобрался. не допилили все таки. дошел до https://github.com/yiisoft/yii2/pull/11646
а такие были надежды…эхх зря полчаса потратил