What does the CustomerStore model look like?
Strange query on updateOrCreate
Hey guys, im using updateOrCreate to update a pivot table with a mass of entries. The queries that will be executed are wrong and i have no idea where it comes from. Maybe some of you have an idea.
The pivot table looks like:
- customer_id
- store_id
- role_id
- last_populate_at
I have an unique index on the three columns customer_id, store_id, role_id (customer_store_customer_id_store_id_role_id_unique)
My call to updateOrCreate values is:
CustomerStore::updateOrCreate([
'customer_id' => $customer->id,
'store_id' => $store->id,
'role_id' => $store->role_id,
],
[
'last_populate_at' => $now,
]);
This call executes the following query:
update customer_store set last_populate_at = 2022-11-09 14:10:14 where '' = 98 and '' = 98
I cant figure at where it comes from and hope you can give me a hint.
regards
@webcodecs syncWithoutDetaching takes the additional attributes:
$customer->stores()->syncWithoutDetaching([
$store->id => ['role_id' => $store->role_id, 'last_populate_at' => $now]
]);
Please or to participate in this conversation.