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

'as_document' does not contain symbolized keys for in-memory documents

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0
    • Affects Version/s: 5.1.3
    • Component/s: None
    • Labels:
      None

      When pulling objects from the database, the 'as_document' returned hash has both symbols and strings as keys, however for in-memory documents the hash contains only string keys. For example

      class Search
      include Mongoid::Document
      field :name, type: String
      end

      Search.new(name: "test").as_document["name"] => "test"
      Search.new(name: "test").as_document[:name] => nil
      Search.create(name: "test").as_document["name"] => "test"
      Search.create(name: "test").as_document[:name] => nil
      Search.first.as_document[:name] => "test"
      Search.first.as_document["name"] => "test"

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            clarkgr George L
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: