-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
ruby require 'mongoid' class Foo include Mongoid::Document field :flag, type: Boolean end foo = Foo.new(flag: "true") foo.flag
In 3.x, foo.flag is coerced to a Boolean and stored as such.
1.9.3-p385 :022 > foo = Foo.new(flag: "true") => #<Foo _id: 526a73633b5552cd6b000001, flag: true> 1.9.3-p385 :023 > foo.flag => true
In master, foo.flag is not coerced to a Boolean and stored as a string.
1.9.3p385 :009 > foo = Foo.new(flag: "true") => #<Foo _id: 526a738264626c34fe000000, flag: "true"> 1.9.3p385 :010 > foo.flag => "true"
Is this by design? How can I force coercion into a type?
My typical scenario is a web-based POST, and having booleans become booleans makes it really simple, a query string "flag=true" becomes a "true" string by default.