Module: ActiveRecord::Relation::SafeQuery
- Included in:
- ActiveRecord::Relation
- Defined in:
- lib/safe_query.rb
Defined Under Namespace
Modules: QueryRegistry
Instance Method Summary collapse
Instance Method Details
#each ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/safe_query.rb', line 14 def each QueryRegistry.reset super query_to_check = QueryRegistry.queries.first.to_s unless query_to_check.blank? || query_to_check.upcase.include?("LIMIT ") || query_to_check.upcase.include?("IN ") raise UnsafeQueryError, "Detected a potentially dangerous #each iterator on an unpaginated query. " + "Perhaps you need to add pagination, a limit clause, or use the ActiveRecord::Batches methods. \n\n" + "To ignore this problem, or if it is a false positive, convert it to an array with ActiveRecord::Relation#to_a before iterating.\n\n" ++ "Potentially unpaginated query: \n\n #{query_to_check}" end end |