-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
mongoid 3.0.1
I want to get first post with its blog, but the eager loading fetches all posts' blogs
Post.includes(:blog).first
<pre>MOPED: 127.0.0.1:27017 QUERY database=blog_dev collection=posts selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 fields=nil (0.2942ms)
MOPED: 127.0.0.1:27017 QUERY database=blog_dev collection=posts selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[] limit=0 skip=0 fields=
MOPED: 127.0.0.1:27017 GET_MORE database=blog_dev collection=posts limit=0 cursor_id=1656386615102804572 (1.2517ms)
MOPED: 127.0.0.1:27017 QUERY database=blog_dev collection=blogs selector={"_id"=>{"$in"=>["500e398c6abd0e3f1b000095", "500e398c6abd0e3f1b00009d", "500e398c6abd0e3f1b0000a8", ...]}} flags=[] limit=0 skip=0 fields=nil (2.3420ms)</pre>
The expected behavior is like the following query
Post.includes(:blog).limit(1).first
<pre>MOPED: 127.0.0.1:27017 QUERY database=blog_dev collection=posts selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 fields=nil (0.2904ms)
MOPED: 127.0.0.1:27017 QUERY database=blog_dev collection=posts selector={"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[] limit=1 skip=0 fields={"blog_id"=>1}
(0.1476ms)
MOPED: 127.0.0.1:27017 QUERY database=blog_dev collection=blogs selector={"_id"=>{"$in"=>["500e398c6abd0e3f1b000095"]}} flags=[] limit=0 skip=0 fields=nil (0.1788ms)</pre>
BTW, the behavior of eager loading for one-to-many is right