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

Closed
bquorning opened this Issue Mar 6, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@bquorning
Contributor

bquorning commented Mar 6, 2014

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

This comment has been minimized.

Show comment Hide comment
@dmathieu

dmathieu Mar 6, 2014

Contributor

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.

Contributor

dmathieu commented Mar 6, 2014

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

This comment has been minimized.

Show comment Hide comment
@bquorning

bquorning Mar 7, 2014

Contributor

Thanks 👍

Contributor

bquorning commented Mar 7, 2014

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment