Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1482

Accessing referenced children of a model at initialization causes invalid query

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.0
    • Affects Version/s: None
    • Component/s: None

      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)}}

            Assignee:
            Unassigned Unassigned
            Reporter:
            sandstrom sandstrom
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: