mongoid/mongoid — Issue #1804: Embedded document class removal causes NameError on old data.
Author: thedracle
Created: 2012-03-08 21:07:48+00:00
State: open

Perhaps the following change to automatically create a class including MongoId::Document would be a reasonable alternative to the above issue?

mongoid-2.4.4/lib/mongoid/relations/metadata.rb:
def klass
begin
@klass ||= class_name.constantize
rescue NameError => e
puts e
if e.inspect =~ /uninitialized constant (\w+)/
c = Class.new do
include Mongoid::Document
end
Kernel.const_set class_name, c

@klass = class_name.constantize
end
end
@klass
end