Circumstances
I have three models / db tables associated with 1: n each: An order has several commissions , and the commission has several commission_positions . Therefore, in the Commission_position field there is an FK field containing the commission identifier. The commission itself has an FK field containing the order identifier.
Order> Commission> Commission
Problem
What I need to do now is to select all the objects that have a certain value in the corresponding order model. The obvious solution is to use the Query-Object of CommissionPosition, which I expanded with a named scope. The named parameter is as follows:
class CommissionPositionQuery extends ActiveQuery { public function alphaOrderId($id) {
The commission relation is defined on the Commission model and works. The second order relation is also defined on the commission model and works. The filtered alpha_order_id field is in the order table. Now I execute the request as follows:
$filteredPositions = CommissionPosition::find()->alphaOrderId(17)->all();
The scope is called successful, and where part is used, but when I check the generated SQL, I don't see any connection statements, although I use the with method to tell yii to get the relationship together. The answer is an "unknown alpha_order_id column", which makes sense since there is no join to the linked tables. This is the generated SQL:
SELECT * FROM `commission_position` WHERE (`alpha_order_id`=17)
What am I missing? Is this a Yii2 bug?
source share