-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Support created_at timestamps on upserts #34712
Conversation
Should we update |
@taylorotwell, I've added |
I still don't really understand this method. Assume I have a I want to bulk edit my post titles and upsert the posts... any new records should be inserted with a created at timestamp. I can't do this: $results = Post::upsert([
['slug' => 'foo', 'title' => 'foo updated'],
['slug' => 'bar', 'title' => 'bar updated'],
], 'slug'); What am I supposed to do? |
@taylorotwell for that case, you'd have to do this: $results = Post::upsert([
['slug' => 'foo', 'title' => 'foo updated'],
['slug' => 'bar', 'title' => 'bar updated'],
], 'slug', ['title']); |
Pulls in the work by @paras-malhotra in laravel/framework#34698 & laravel/framework#34712 for use in October CMS.
Based off implementation done in laravel/framework#34698 and laravel/framework#34712.
Pulls in the work by @paras-malhotra in https:ithub.com/laravel/framework/pull/34698 & laravel/framework#34712 for use in October CMS. Co-authored-by: Ben Thomson <git@alfreido.com>
Amazing work, I love it! This PR also adds the possibility to define the value when a row is being updated, and it allows DB expressions. It is awesome, for example, you can add numbers: Stats::upsert(
[
['id' => 1, 'page_views' => 1],
['id' => 2, 'page_views' => 5],
],
'id',
[
'page_views' => DB::raw('stats.page_views + excluded.page_views'),
]
); It works for Postgres |
As a follow-up to #34698, this PR adds support for updating
created_at
timestamps on upserts.I've modified the signature of the
upsert
method to include an optional third argument to be an array of the columns to be updated. If not provided, all columns will be updated.