Integer type doesn't coerce stored value into an Integer

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • 3.0.20
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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?

            Assignee:
            Unassigned
            Reporter:
            gshiftlabs-dbuttineau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: