Skip to content
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

Columns with database defaults are not updated #98

Open
sjorsbranderhorst opened this issue Oct 29, 2019 · 1 comment
Open

Columns with database defaults are not updated #98

sjorsbranderhorst opened this issue Oct 29, 2019 · 1 comment

Comments

@sjorsbranderhorst
Copy link
Contributor

sjorsbranderhorst commented Oct 29, 2019

We found that when

  1. having a default in the database (here for a table called hardwares)

    ┌─────────┬─────────────────┬────────
    │ Column │ Type │ Default
    ├─────────┼─────────────────┼─────────
    │ id │ integer │ ...
    │ prio │ integer │ 999

  2. having an existing entry in the database with a non default value for prio like: 998 with id: 1

That upserting like so:

hw = { id: 1, prio: 999 }
id = Hardware.new(prio: hw[:prio]).upsert.id

won't mention the prio column in the ON CONFLICT part resulting in no update. However, when upserting like so:

id = Hardware.upsert(prio: hw[:prio]).id

did indeed update the record in the database (back to its default value). Am not sure if this is (a bug/an issue), but thought I would drop this here. Thanks for all the work on the nice Gem!

@olleolleolle
Copy link
Collaborator

Thanks for explaining!

Could you make the above into a part of our README - as a Pull Request? It's a sort of workaround/explanation of behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants