- 
  Notifications
 You must be signed in to change notification settings 
- Fork 1.4k
-
I have a PurchaseRequest (like a Cart) and inside I have products...
{
 "id": "62862f04375eed096c6abc32",
 "products": [
 {
 "id": "628667dccee1aa7afe760d24",
 "currency": "MXN",
 "unit_cost": 10,
 "product_id": 1,
 "quantity": 1,
 "metadata": []
 }
 ]
}
I am not able to update just the position 0 of the array products.
I tried with:
$purchaseRequest->update(['products' => [$currentProductIndex => $currentProduct]]);
But this replaces the whole products.
I tried with:
$purchaseRequest->update(['products.' . $currentProductIndex => $currentProduct]);
But it doesn't do anything.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I've solved it by debugging but I came across another bug...
PurchaseRequest::where(
 [
 ['_id', '=', new ObjectId($purchaseRequestId)],
 ['products.id', '=', $productId]
 ]
)->update(
 [
 '$set' => [
 "products.$" => $currentProduct,
 ]
 ]
);
I am using the timestamps for update, created and deleted and it is causing the following error, setting $set inside $set
src/Query/Builder.php
So I had to remove the $set inside my update statement, and leave only products.$
Beta Was this translation helpful? Give feedback.