rails/rails — pull request #10966 by davejachimiak (2013-06-16 20:51:51+00:00)
Title: Act on default scope in #unscope and #except

#### Hello!

This pull addresses a couple, but not all, issues noted here: https://github.com/rails/rails/issues/10643.

Currently, `#unscope` and `#except` do not act on the default scope. (Default scope is always applied at the end of a query. Whether or not the default scope has been applied before the end of a query chain is stored as `#default_scoped` on the relation. (`#default_scoped?` is aliased to `#default_scoped`.))

##### `#unscope`
This pull executes `#unscope`'s existing code with the scope returned from `#with_default_scope`. It changes a few variable names (`scope` -> `arg` in `#unscope`, `scope` -> `clause` in `#symbol_unscoping`) to avoid confusion over the meaning of word "scope."

##### `#except`
Currently, `#except` returns a brand new Relation based on what's passed in and the current relation's `#values`. If any clause passed in is included in the default scope, this pull executes `#unscope` with those clauses on that relation. The spirit of `#except` seems to be *fresher* than `#unscope` in that it originally returned a brand new Relation. That is why this only calls unscope if any clauses passed in are in the default scope, rather than just calling `#unscope` with the clauses passed in.

This pull's version of `#except` queries the default scope's values. Because such values feel public, this pull adds `#default_scope_values` as a public method. Some in the core may object to its implementation because of the evolution around default scopes in general and deprecations re: eager loading default scopes in particular.

This is my first pull request to rails. :saxophone::racehorse: