mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Move scoping
handling into klass level from relation
I'd like to use this `scoping` handling on klass level to address unwanted internal scoping issues.
This commit is contained in:
parent
334c4c533f
commit
4895e5cfc7
2 changed files with 9 additions and 5 deletions
|
@ -315,10 +315,7 @@ module ActiveRecord
|
|||
# Please check unscoped if you want to remove all previous scopes (including
|
||||
# the default_scope) during the execution of a block.
|
||||
def scoping
|
||||
previous, klass.current_scope = klass.current_scope(true), self unless @delegate_to_klass
|
||||
yield
|
||||
ensure
|
||||
klass.current_scope = previous unless @delegate_to_klass
|
||||
@delegate_to_klass ? yield : klass._scoping(self) { yield }
|
||||
end
|
||||
|
||||
def _exec_scope(*args, &block) # :nodoc:
|
||||
|
|
|
@ -31,7 +31,14 @@ module ActiveRecord
|
|||
# Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10"
|
||||
# }
|
||||
def unscoped
|
||||
block_given? ? relation.scoping { yield } : relation
|
||||
block_given? ? _scoping(relation) { yield } : relation
|
||||
end
|
||||
|
||||
def _scoping(relation) # :nodoc:
|
||||
previous, self.current_scope = current_scope(true), relation
|
||||
yield
|
||||
ensure
|
||||
self.current_scope = previous
|
||||
end
|
||||
|
||||
# Are there attributes associated with this scope?
|
||||
|
|
Loading…
Reference in a new issue