instance method
scoping
Ruby on Rails 6.1.7.10
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 405
def scoping
already_in_scope? ? yield : _scoping(self) { yield }
end
Defined in activerecord/lib/active_record/relation.rb line 405
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation