Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Issue with default_scope and eager loading #1987

stantona opened this Issue · 5 comments

3 participants


I have a Blog model like:

class Blog
   has_many :posts
   default_scope includes(:posts)

so that posts are eagerly loaded when a Blog query is made.

I experience unexpected behaviour if I query for the same blog > 1 times. It seems like the post data are reapplied to the array, so that the array contains duplicates of the posts.

Is this expected behaviour?

Please let me know if you need more info.


So you're just doing something like...




Yes that's right. I noticed this when looking a bug in our code, and then using pry to see what's going on and noticed the elements being duplicated in the posts array.


Ok I'll have a look, thanks.


I reproduce the issue in a rspec failure :


This spec works on Mongoid 3 master branch.

@durran durran closed this in db472a6
@durran durran referenced this issue from a commit
@durran durran Bring #1987 into master 052349c
@vpuzzella vpuzzella referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.