You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When primary model has a relation that uses inverseOf, "finding" primary model as an object with relation as array produces PHP error. All other combinations of object/array for primary model and relation work fine.
$customers[$i]['orders'] calls class method returning a simple PHP array (no objects). Modifying that array will create a copy of an array and have no effect on the value stored in $customers[$i] object. This is what PHP complains about.
The easy solution would have been:
// Access array directly (not through some hidden class method):$primaryModels[$i][_related'][$primaryName][$j][$name] = $primaryModel;
// $customers[$i][_related']['orders'][$j]['customer'] = $customer;
But that solution won't work because ActiveRecord::_related is a private property.
The bad solution with lots of array copying would be something like:
The better solution might be to fill in inverseOf related data BEFORE calling populateRelation() on primary models in ActiveRelationTrait::populateRelation().
Or change _related property scope from private to protected.
Won't help because this property needs to be accessed in a different class (_related is a property of \yii\db\BaseActiveRecord and access needs to be in yii\db\ActiveQuery::populateInverseRelation().
When primary model has a relation that uses
inverseOf
, "finding" primary model as an object with relation as array produces PHP error. All other combinations of object/array for primary model and relation work fine.What steps will reproduce the problem?
What is the expected result?
The last line executes without errors.
What do you get instead?
PHP error: "Indirect modification of overloaded element of Customer has no effect" in
yii\db\ActiveQuery::populateInverseRelation()
.Additional info
The text was updated successfully, but these errors were encountered: