-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated upsert guides with extra methods for created and updated chec…
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,23 @@ class Guides::Database::SavingRecords < GuideAction | |
end | ||
``` | ||
### Detecting updated or created | ||
Since an `upsert` will attempt to find first and then update when found, you may want to know if the operation | ||
performed a create or an update. You can use `created?` or `updated?` on the operation to get this value. | ||
```crystal | ||
SaveUser.upsert(name: "Will", email: "[email protected]") do |operation, user| | ||
operation.created? # => true | ||
operation.updated? # => false | ||
end | ||
SaveUser.upsert(name: "William", email: "[email protected]") do |operation, user| | ||
operation.created? # => false | ||
operation.updated? # => true | ||
end | ||
``` | ||
#{permalink(ANCHOR_SAVING_SERIALIZED_JSON)} | ||
## Saving Serialized JSON | ||
|