instance method
scoping
Ruby on Rails 4.2.9
Since v3.0.20Signature
scoping()
Scope all queries to the current scope.
Comment.where(post_id: 1).scoping do
Comment.first
end
# => SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = 1 ORDER BY "comments"."id" ASC LIMIT 1
Please check unscoped if you want to remove all previous scopes (including the default_scope) during the execution of a block.
Source
# File activerecord/lib/active_record/relation.rb, line 299
def scoping
previous, klass.current_scope = klass.current_scope, self
yield
ensure
klass.current_scope = previous
end
Defined in activerecord/lib/active_record/relation.rb line 299
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation