mongoid/mongoid — Issue #1481: Accessing referenced children of a model at initialization causes invalid query
Author: sandstrom
Created: 2011-12-06 19:18:51+00:00
State: open

When accessing referenced children of a model at initialization an invalid query is constructed. See the code below for a test case:

class Nut

include Mongoid::Document

end

class Squirrel

include Mongoid::Document

references_and_referenced_in_many :nuts, :class_name => "Nut", :validate => false

def test=(aaa)
self.nuts.inspect # breaks
end

end

Step to Reproduce (type into the console)

* `Squirrel.new({ :test => "hello" })`

The above will cause the following error `Mongo::OperationFailure: invalid query`, and the invalid query is `MONGODB dev['nuts'].find({:_id=>{"$in"=>nil}})`