N
N
Nikolay2015-11-18 12:51:12
Yii
Nikolay, 2015-11-18 12:51:12

Why doesn't Yii2 allow using ActiveQueryInterface in attributes?

If there is a code in AR

/**
* @return ActiveQuery
*/
public function getLabel()
{
    // какой-то код
}

Then you can get ActiveQuery only in this way
$AR->getLabel()if you access through $AR->label, then there will be no ActiveQuery anymore, because. the method __get BaseActiveRecord.php will not miss
it. Is it impossible to do so?
UPD. Found a mention in the documentation .
Note: While this concept looks similar to the object property feature, there is an important difference. For normal object properties the property value is of the same type as the defining getter method. A relation method however returns an yii\db\ActiveQuery instance, while accessing a relation property will either return a yii\db\ActiveRecord instance or an array of these.

As a consequence, this behavior is relevant for any method, even if no relationships are used internally.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay, 2015-11-18
@izheme

Note: While this concept looks similar to the object property feature, there is an important difference. For normal object properties the property value is of the same type as the defining getter method. A relation method however returns an yii\db\ActiveQuery instance, while accessing a relation property will either return a yii\db\ActiveRecord instance or an array of these.
Yii2 docs
I have no connections, but the same logic applies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question