Sha256: 7d6c5d66fff3a7dd70e4d744195b0fc359b0f2616e8795a47745b33525dcb43b

Contents?: true

Size: 802 Bytes

Versions: 3

Compression:

Stored size: 802 Bytes

Contents

module GroupedScope
  module HasManyAssociation
    
    def self.included(klass)
      klass.class_eval do
        alias_method_chain :construct_sql, :group_scope
      end
    end
    
    def construct_sql_with_group_scope
      if @reflection.options[:grouped_scope]
        if @reflection.options[:as]
          # TODO: Need to add case for polymorphic :as option.
        else
          @finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} IN (#{@owner.group.quoted_ids})"
          @finder_sql << " AND (#{conditions})" if conditions
        end
        @counter_sql = @finder_sql
      else
        construct_sql_without_group_scope
      end
    end
    
    
  end
end

ActiveRecord::Associations::HasManyAssociation.send :include, GroupedScope::HasManyAssociation

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
decisiv-grouped_scope-0.6.0.1 lib/grouped_scope/has_many_association.rb
metaskills-grouped_scope-0.6.0 lib/grouped_scope/has_many_association.rb
grouped_scope-0.6.1 lib/grouped_scope/has_many_association.rb