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

'Includes' bug for Mongoid 3

      This bug exists only in Mongoid 3 (testing on 3.0.15). Mongoid 2 doesn't have the bug.

      foo = City.includes(:country).limit(3)
      foo.first
      MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (1.5016ms)
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=places selector={"$query"=>{"deleted_at"=>nil, "_type"=>{"$in"=>["City"]}}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 fields=nil (5.1830ms)
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=places selector={"deleted_at"=>nil, "_id"=>

      {"$in"=>["4eda5f2c8792904be40000fc"]}

      , "_type"=>{"$in"=>["Country"]}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.6833ms)

      So it selects just one country for the first city instead of selecting all the three countries.

      bar = foo.to_a
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=places selector={"$query"=>{"deleted_at"=>nil, "_type"=>{"$in"=>["City"]}}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=3 skip=0 fields=nil (4.3747ms)
      MOPED: 127.0.0.1:27017 KILL_CURSORS cursor_ids=[9172683583138442393] (0.1442ms)

      bar.last.country
      MOPED: 127.0.0.1:27017 QUERY database=gocheap_development collection=places selector={"$query"=>{"deleted_at"=>nil, "_id"=>"4eda5f2c8792904be40000c7", "_type"=>{"$in"=>["Country"]}}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 fields=nil (0.8352ms)

      So all the other cities have to make separate requests for their countries as the Criteria is already affected by 'first'.

            Assignee:
            durran Durran Jordan
            Reporter:
            exoth Yuriy Trofimenko
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: