You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior
A clear and concise description of what you expected to happen.
If the item is new, the default values should be applied. This is like create.
If the item already exists, the default values should not be applied. This is like update.
Am I understanding upsert correctly?
There are two cases to consider:
does the item exist?
yes: do not overwrite field with default value
no: create new item with default values
does the field on the item exist?
yes: do not overwrite field with default value
no: do not overwrite field with default value
I think 2) could be fixed by using field = if_not_exists(field, field_default_value). This should update the field only if it doesn't exist. However, I'm not sure if/how 1) could be fixed. If it's not fixable, maybe it could be added to the docs that upsert differs from update in that it always applies default values.
The text was updated successfully, but these errors were encountered:
This is an improvement that has been considered (I thought there might have been an existing issue for this?), and it is an ideal state. I remember looking into implementing this and finding that it would required a non-trivial refactor of some parts of the library to know if a value was provided vs set via "default". Here is how you can ensure the value is not overridden by a default, it's not as ideal as the library handling it under the hood but it does prevent the issue bring up.
I'd like to keep this ticket open so I can prioritize it in my backlog, which is deeper than I'd like right now. Thank you for reporting this!
Describe the bug
A clear and concise description of what the bug is.
The
default
value or function will always be applied onupsert()
, even if the item already exists. This will potentially override existing values.ElectroDB Version
Specify the version of ElectroDB you are using
(e.g.
1.8.4
)latest
ElectroDB Playground Link
Playground
Entity/Service Definitions
See playground
Expected behavior
A clear and concise description of what you expected to happen.
If the item is new, the default values should be applied. This is like
create
.If the item already exists, the default values should not be applied. This is like
update
.Am I understanding
upsert
correctly?There are two cases to consider:
I think 2) could be fixed by using
field = if_not_exists(field, field_default_value)
. This should update the field only if it doesn't exist. However, I'm not sure if/how 1) could be fixed. If it's not fixable, maybe it could be added to the docs thatupsert
differs fromupdate
in that it always applies default values.The text was updated successfully, but these errors were encountered: