-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
This took a bit for us to figure out. The Integer extension doesn't attempt to coerce the type of the field coming back from Mongo.
If you insert into a collection via the mongo command line, the Mongoid model will render it as a float rather than an integer.
For instance:
db.bands.insert( { name: "Robin's Merry Men", album_count: 1 })
Have a model defined like so:
class Band include Mongoid::Document field :name, type: String field :album_count, type: Integer end
Pull the object out:
band = Band.where( name: "Robin's Merry Men" ).first
Check the album coin
pp band.album_count
We'll get 1.0
It would probably be advantageous to have the Integer extension coerce the value returned to an integer if the field type has been defined that way?