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

Type casting fails when the database has been edited from elsewhere

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

      I have found that if I for example declare a symbol field, it will be retrieved from the database as a symbol just fine, until you edit the document with an editor like RockMongo, MongoHub or PHPMoAdmin, in which case it turns into a string. This happens even if you don't really change anything, but just click edit and then save.

      I just tried this with a new Rails 3.1.3 app on Ruby 1.9.3 on OS X:

      1.9.3p0 :001 > Profile.create(:gender => :male)
      => #<Profile _id: 4ee763a235f5b2b544000001, _type: nil, gender: :male>
      1.9.3p0 :002 > Profile.first.gender
      => :male

      Then I opened the document in Rockmongo and MongoHub (on separate occasions) and just re-saved the document without changing anything.

      Then I tried this:

      1.9.3p0 :003 > Profile.first.gender
      => "male"

      Here is my model code:

      class Profile
      include Mongoid::Document
      field :gender, :type => Symbol
      end

      This in turn causes lots of trouble for plugins like symbolize which require that symbol fields really are symbols, or else validation will fail.

            Assignee:
            Unassigned Unassigned
            Reporter:
            johanlindblad johanlindblad
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: