Hi,
I define a new class that extends ActiveQuery with a method myScope() that do something.
So I can write myModel::find()->myScope(). And that’s work correctly.
MyModel has an hasMany() relation with an other model , public function getRelationName() {}
Now the problem is I can’t write myModel::find()->relationName->myScope() because getRelationName() return me an array of ActiveRecord object, It’s not an ActiveQuery object.
It only works if I write myModel::find()->getRelationName()->myScope() but I don’t want call the relation in this way.
Any suggestions?
Thx
$x = Costumers::find()->with(‘addressColl’)->where([’=’, ‘Id’, ‘012345’])->one();
$lastAddress = $x->addressColl->onlyPresent()->all();
//-------------------------
The code upper doesn’t work…
Please, explain me better what about your suggestion.
Thx
Roberto
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.
$customer->orders; // is an array of `Order` objects
$customer->getOrders(); // returns an ActiveQuery instance