Skip to content

Why does upsert_all disallow unique_by primary key? #40059

@kapso

Description

@kapso

I am looking to batch UPDATE... on my database, and found upsert_all. But it seems you cannot upsert using the primary key, so something like this...

Product.upsert_all([{id: 1, order_count: 23}, {id: 93, order_count: 67}], unique_by: :id)

...results in the following error - ArgumentError (No unique index found for id)

Curious why does upsert_all disallows updates by primary key. BTW, I did try unique_by: :products_pkey as well but that did not work either.

System configuration

Rails version: 6.0.3.2

Ruby version: 2.7.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions