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

using custom _id fields failing in 3.0.3

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

      Hi,

      I'm in the process of upgrading to Mongoid 3.0.3 from Mongoid 2. I'm having trouble with custom :_id field... consider the following class:

      class Feature
        include Mongoid::Document
      
        field :_id, :type => String # we customize this to the name field
        field :enabled, :type => Boolean, :default => false
        field :enabled_organization_ids, :type => Array, :default => []
      end
      

      When I'm trying to create features with the custom :_id I get the following

      jruby-1.6.7 :024 > feature_one = Feature.create(:id => "string")
       => #<Feature _id: , _type: nil, enabled: false, enabled_organization_ids: []> 
      jruby-1.6.7 :025 > feature_two = Feature.create(:_id => "string2")
       => #<Feature _id: , _type: nil, enabled: false, enabled_organization_ids: []> 
      jruby-1.6.7 :026 > Feature.count
       => 2 
      jruby-1.6.7 :027 > Feature.first
       => #<Feature _id: 501830844e6e6f1fa19962a3, _type: nil, enabled: false, enabled_organization_ids: []> 
      jruby-1.6.7 :028 > Feature.last
       => #<Feature _id: 5018308b4e6e6f1fa19962a4, _type: nil, enabled: false, enabled_organization_ids: []> 
      jruby-1.6.7 :029 > feature_one.id
       => nil 
      jruby-1.6.7 :030 > feature_two._id
       => nil 
      jruby-1.6.7 :031 > feature_two.id
       => nil 
      

      This is Rails 3.2.6

            Assignee:
            Unassigned Unassigned
            Reporter:
            tobowers Topper Bowers
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: