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

Updates to an upserted record are not applied #96

Open
bgerami opened this issue Jun 6, 2019 · 0 comments
Open

Updates to an upserted record are not applied #96

bgerami opened this issue Jun 6, 2019 · 0 comments

Comments

@bgerami
Copy link

bgerami commented Jun 6, 2019

After upserting, the very next save on the resulting record does not persist

MyModel.find_by(uuid: 1234) # nil

record = MyModel.new # (id, uuid, name, age)
record.uuid = 1234 # uuid is the upsert_key
result = record.upsert # creates record with uuid 1234

result.update(name: "foo")

persisted = MyModel.find_by(uuid: 1234)
persisted.name # nil

result.update(age: 42)

persisted = MyModel.find_by(uuid: 1234)
persisted.age # 42

The first upsert does an INSERT ON CONFLICT generating the record
The very next update tries to update every column UPDATE "my_model" SET "id" = $1, "name" = $2 ...
Then the update after that does the usual UPDATE "my_model" SET "age" = $1 ...

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

1 participant