Динамический алиас работает? И если работает то как им пользоваться?


Вот это делали когда то, оно еще работает. никто не пользовался?

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]);
}
 $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)

Я делаю это чтоб в один запрос доставать ширину высоту и длину и фильтровать потом

    // длина
    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 прописывать получается? алиасы не работают?

все разобрался. не допилили все таки. дошел до https://github.com/yiisoft/yii2/pull/11646
а такие были надежды…эхх зря полчаса потратил