method

construct_counter_sql

rails latest stable - Class: ActiveRecord::Associations::AssociationCollection

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.0.9) is shown here.

construct_counter_sql()
protected

No documentation available.

# 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/m) { "SELECT #{$1}COUNT(*) FROM" }
          else
            @counter_sql = @finder_sql
          end
        end