Combination between insert_conflict
and validate
#2177
jvanderen1
started this conversation in
General
Replies: 1 comment 1 reply
-
Seems like it would be nice if the validates_unique :email unless @insert_conflict_opts But that seems like accessing private API of the plugin. Maybe if it provided a method like: def insert_conflict?
!!@insert_conflict_opts
end |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using the
:insert_conflict
Sequel model plugin and I believe there may be some difficulty usinginsert_conflict
withvalidate
.For example, says I have the following example model:
Say the following
User
record exists:I would like to update a
User
record if there is a conflicting value foremail
in my case. For example:This unfortunately throws a
Sequel::ValidationFailed
error:Is there any good way to avoid this knowing that we are ignoring the uniqueness of
email
in this case viainsert_conflict
?Workaround 1: Skip Validate In Specific Cases (like
new?
)A workaround I came up with is to define the
User
modelvalidate
method as the following instead:However, this is not ideal as this workaround skips validation regardless of
insert_conflict
being present or not 😦 .Workaround 2: Disable Validation in
save_changes
We could also do this:
However, we would then miss out on other forms of validation unfortunately.
Beta Was this translation helpful? Give feedback.
All reactions