-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
When using a custom id of integer type Mongoid throws an error when finding a document by the string id from the controller parameter.
This code illustrates the problem:
class Band include Mongoid::Document field :band_id, :type => Integer, :type => Integer, default: ->{ Random.rand(10000000000).to_i } field :_id, :type => Integer, default: ->{ band_id } end
Mongoid throws an error if the id is provided as a string from a controller parameter:
1.9.3p194 :007 > Band.create => #<Band _id: 8219652764, _type: nil, band_id: 8219652764> 1.9.3p194 :008 > Band.find("8219652764") Mongoid::Errors::DocumentNotFound: Problem: Document(s) not found for class Band with id(s) 8219652764.