Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

:required doesn't seem to work well on Boolean types #370

Closed
rtyler opened this Issue · 4 comments

5 participants

@rtyler

I'll come back later with a test case but the gist of it here is that a column:

   key :recurring, Boolean, :required => true

When saving that document which has foobar.recurring = false the following failure occurs:

 Validation failed: Recurring can't be blank (MongoMapper::DocumentNotValid)
@bkeepers

Probably using #present? in the validation, which returns false for false.

@ORal

Same here.

@matthiassiegel

MongoMapper seems to work like ActiveRecord here:
http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000083

"If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true"

In my models I always use
validates_inclusion_of :some_boolean_key, :in => [true, false]
and it works fine.

@cheald
Owner

Closed by 4c96d02.

@cheald cheald closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.