-
Notifications
You must be signed in to change notification settings - Fork 233
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
Inconsistant behaviour when validating on a method and not a column #180
Comments
I think the best comparison to make is with |
Though, admittedly in the case of numericality it casts junk as 0 (grrr), so the column doesn't return nil. Basically I consider blank, when there has been no attempt to cast a value to a datetime. But I guess that could be what just I certainly don't want to cast to some dummy value like the number case I outlined. So this interpretation might be in a category all its own. |
In your case, what value is the column being filled with to trigger the validation? |
The column isn't actually filled with junk but with a proper value (a To take the example of
|
The problem happen because the Maybe it would be the case to check the |
I stumbled upon a weird behaviour when trying to use
allow_blank
.We have an
Intervention
model, with a legacystarted_at
column. It also has astarted_at
method (that looks into dependentworking_periods
to compute it).In one instance, the column is filled but the methods returns nil.
The validator doesn't skip the validation since the column is filled but the validation breaks since the method returns
nil
.I think a more coherent behaviour would be to only take into account the method's return value — which is what ActiveModel default validators do.
I think the fix should be around in #validate_each, maybe adjusting the guard-clause or the value setting before the blankness-check.
How to reproduce
The text was updated successfully, but these errors were encountered: