Skip to content
Discussion options

You must be logged in to vote

Hi @StewartLynch, there is a SQL tool called "RETURNING" clauses that allow you to get the data that was just inserted/updated into the database, and our query building library supports it like so:

try database.write { db in 
  model.selectedProperty = try Property
    .upsert { property }
    .returning(\.self)  // 👈
    .fetchOne(db)
}

That allows you to perform the database write and get the freshest value at the same time.

And I'm not entirely sure I understand the problem you are having when you say "selectedProperty is not updated", but if you only want to update the selectedProperty field of your model after the database transaction finishes, then you can do so like this:

model.sel…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@StewartLynch
Comment options

Answer selected by StewartLynch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants