Flowdock
method

construct_counter_sql

Importance_0
v3.0.5 - Show latest stable - 0 notes - Class: ActiveRecord::Associations::AssociationCollection
construct_counter_sql() protected

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/associations/association_collection.rb, line 382
        def construct_counter_sql
          if @reflection.options[:counter_sql]
            @counter_sql = interpolate_and_sanitize_sql(@reflection.options[:counter_sql])
          elsif @reflection.options[:finder_sql]
            # replace the SELECT clause with COUNT(*), preserving any hints within /* ... */
            @counter_sql = interpolate_and_sanitize_sql(@reflection.options[:finder_sql]).sub(/SELECT\b(\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" }
          else
            @counter_sql = @finder_sql
          end
        end
Register or log in to add new notes.