Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2524

Storing a Date inside a field of type Array returns a Time

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.11
    • Affects Version/s: None
    • Component/s: None

      We store a field of variable types. It can be an array of String, Date or Time in any quantity and combinations.

       ruby
      class Artwork
        include Mongoid::Document
      
        field :dates, type: Array
      end
      

      Mongoid 2.x

       ruby
      Artwork.new({ dates: [ Date.parse("3/5/2011") ]}).dates.first.class
       => Date
      

      Mongoid 3.x

       ruby
      Artwork.new({ dates: [ Date.parse("3/5/2011") ]}).dates.first.class
       => Time 
      

      Is this by design or a bug? I would expect that storing a date returns a date. Is there an easy way to get old behavior back?

            Assignee:
            Unassigned Unassigned
            Reporter:
            dblock Daniel Doubrovkine
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: