-
Notifications
You must be signed in to change notification settings - Fork 28
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
allow_nil not working? #15
Comments
seems it doesn't work also when I use both and allow_nil at the same time |
+1 |
1 similar comment
+1 |
I came across this from an issue on SO I cloned the project, wrote a simple test to verify that it wouldn't save if the value was bogus, and verified that as soon as you add allow_nil => true, it will always save....NO MATTER WHAT. I debugged a bit and verified that the code is not even called at all if you set allow_nil => true. I'm not sure why that is, probably something with how the validators are registered and called in a higher-level spot, but there is a work around that I was able to use. If I used this, my test would behave properly (invoke the logic if the value was not nil, skip it otherwise), and the record would not save if there is a non-nil, but not valid value: validates_existence_of :name, :unless => Proc.new { |user| user.name_id.blank? } |
use validates :state, :existence => true, :allow_nil => true |
I might be misunderstanding it's usage, but given the following code:
Should the parent existence only be checked if a value is provided? In other words, if it's nil no validation should take place correct?
For some reason when I add the allow_nil option block it does indeed allow nil, but it also allows me to enter any erroneous value without any existence validations kicking in.
The text was updated successfully, but these errors were encountered: