mongoid/mongoid — Issue #1474: nil problem for some embedded collections
Author: digitalplaywright
Created: 2011-12-04 12:54:59+00:00
State: open

Hi,

An embedded collection used in conjunction with class inheritance produce a nil error for some documents in our database (not all):
- undefined method `[]' for nil:NilClass
when accessed. There is data in the database for the embedded collection and it looks OK. It only does this for a minority of the documents. Please let me know if you have any tips on how to debug this.

The embedded collection use inheritance like this:

class CacheBase
include Mongoid::Document
include Mongoid::Timestamps

embedded_in :cachebase_cacheable, polymorphic: true
end

class A < CacheBase

end

class C
include Mongoid::Document
include Mongoid::Timestamps

embeds_many :a_interactions, :class_name => "A", as: :cachebase_cacheable

end

Please let me know if you have any tips on how to debug this or what the cause may be.