Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue with default_scope and eager loading #1987

Closed
stantona opened this Issue · 5 comments

3 participants

@stantona

I have a Blog model like:

class Blog
   has_many :posts
   default_scope includes(:posts)
end

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.

@durran
Owner

So you're just doing something like...

Blog.find(id)
Blog.find(id)

?

@stantona

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.

@durran
Owner

Ok I'll have a look, thanks.

@shingara

I reproduce the issue in a rspec failure :

https://gist.github.com/2643623

@shingara

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.