-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
This works:
class Library include Mongoid::Document identity :type => Integer end class Book include Mongoid::Document belongs_to :library end Library.delete_all Book.delete_all library = Library.create!(:id => 1) Book.create!(:library_id => 1) p Book.first.library
prints
#<Library _id: 1, _type: nil>
But if you change it to this:
Book.create!(:library_id => "1")
It fails:
nil
Why does this matter? Oftentimes in Rails you use params to create/update Mongoid objects. Params are always strings. So if you change your identity type from BSON::ObjectId to Integer, things suddenly stop working. You can workaround the bug by using callbacks to set the correct type, but that seems like a hack.