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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 5.1.3
    • Fix Version/s: 6.0.0
    • Component/s: None
    • Labels:
      None

      Description

      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"

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: