Suppose I have 2 models of AR. 1. Payment - payments 2. Cart - shopping cart
And accordingly, at payment
public function getCarts() { return $this->hasMany(Cart::className(), ['payment_id' => 'id']); } The task is as follows. I need to merge the basket of the second payment with the basket of the first.
those.
$first_payment = Payment::findOne($first_payment_id); $second_payment = Payment::findOne($second_payment_id); And combine:
$first_payment->carts = array_merge($first_payment ->carts, $second_payment->carts); And of course with this approach, I catch the error:
Setting read-only property: frontend\models\Payment::carts That is basically logical.
Tell me how best to overwrite this property?