Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Misleading documentation for ActiveRecord::Scoping::Default.unscoped #14294

Closed
bquorning opened this Issue · 2 comments

3 participants

@bquorning

The documentation says that .unscoped “Returns a scope for the model without the default_scope”, giving the following examples:

Post.all          # Fires "SELECT * FROM posts WHERE published = true"
Post.unscoped.all # Fires "SELECT * FROM posts"

However, the following example would also be valid:

Post.where(id: 42).unscoped.all # Fires "SELECT * FROM posts"

Notice how the where condition is removed along with the default scope.

And an example with associations:

class Category < ActiveRecord::Base
  has_many :posts
end

category = Category.find(42)

category.posts.all          # Fires "SELECT * FROM posts WHERE published = true AND category_id = 42"
category.posts.unscoped.all # Fires "SELECT * FROM posts"

Again, notice how the association information is removed along with the default scope.

I am unsure of whether this is just a documentation issue, or if it is an actual bug.

@dmathieu
Collaborator

This would be kind of a documentation issue. unscoped removes all scopes previously defined.
Please feel free to fix the phrasing and open a pull request.

@bquorning

Thanks :+1:

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.