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

Upsert operations should tell you if a record was created or updated #888

Closed
jwoertink opened this issue Oct 7, 2022 · 2 comments
Closed
Labels
easy/high impact feature request A new requested feature / option

Comments

@jwoertink
Copy link
Member

When you're using an upsert, you may want to know whether the record that comes back was an updated record or a new record.

SaveGoal.upsert(title: "Some goal", amount: 100) do |operation, goal|
  # maybe something like this?
  operation.created? #=> false
  operation.updated? #=> true
end

This could really hook in to all SaveOperation too.

SaveGoal.create(...) do |o, g|
  o.created? #=> true
  o.updated? #=> false
end

SaveGoal.update(...) do |o, g|
  o.created? #=> false
  o.updated? #=> true
end

We already have operation.saved?

enum OperationStatus
Saved

@jwoertink jwoertink added feature request A new requested feature / option easy/high impact hacktoberfest Valid Issue for Hacktoberfest labels Oct 7, 2022
davidepaolotua added a commit to davidepaolotua/avram that referenced this issue Oct 25, 2022
Implements luckyframework#888.
Adds two new boolean methods to SaveOperation.
They work similarly to new_record? but always return false if the
record was not persisted (e.g: failed save or not-yet-performed
operation)
@jwoertink
Copy link
Member Author

One thing I forgot to consider on this.... What are the results when the save fails? I guess if you're calling create and it fails to create then created? just returns false, and same for updated? 🤔

jwoertink pushed a commit that referenced this issue Oct 27, 2022
Implements #888.
Adds two new boolean methods to SaveOperation.
They work similarly to new_record? but always return false if the
record was not persisted (e.g: failed save or not-yet-performed
operation)
@jwoertink jwoertink removed the hacktoberfest Valid Issue for Hacktoberfest label Nov 6, 2022
jwoertink pushed a commit that referenced this issue Dec 2, 2022
* Add updated? and created? methods on SaveOperations

Implements #888.
Adds two new boolean methods to SaveOperation.
They work similarly to new_record? but always return false if the
record was not persisted (e.g: failed save or not-yet-performed
operation)

* Implement date function

* Move upper and lower to new criterias

* generalize the application of functions to columns

* Put in standby the extra-param function creation

* Final clean up
@jwoertink
Copy link
Member Author

This is now done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy/high impact feature request A new requested feature / option
Projects
None yet
Development

No branches or pull requests

1 participant