D
D
di2020-08-28 18:17:43
Yii
di, 2020-08-28 18:17:43

The own implementation of ActiveQuery does not work correctly. Why?

Has its own ActiveQuery

class ValueQuery extends ActiveQuery
{
    public function forProduct($product_id): ValueQuery
    {
        return $this->andWhere(['product_id' => $product_id]);
    }

    public function forCharacteristic($characteristic_id): ValueQuery
    {
        return $this->andWhere(['characteristic_id' => $characteristic_id]);
    }
}


Another ActiveRecord Product has a getter
public function getValuesForCard(): ActiveQuery
    {
        $characteristics = CategoriesCharacteristics::find()
            ->select('characteristic_id')
            ->forCategory($this->category_id)
            ->forList(CatCharList::ATTR_LIST_CARD)
            ->orderBy(["sort" => SORT_ASC]);
        return Value::find()
            ->forProduct($this->id)
            ->forCharacteristic($characteristics);
    }


When I call $product->valuesForCard in the view, I suddenly get one model instead of an array of models. Why??? how to fix?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question