Module: GroupedScope::HasManyThroughAssociation

Defined in:
lib/grouped_scope/has_many_through_association.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
8
# File 'lib/grouped_scope/has_many_through_association.rb', line 4

def self.included(klass)
  klass.class_eval do
    alias_method_chain :construct_conditions, :group_scope
  end
end

Instance Method Details

#construct_conditions_with_group_scopeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/grouped_scope/has_many_through_association.rb', line 10

def construct_conditions_with_group_scope
  conditions = construct_conditions_without_group_scope
  if @reflection.options[:grouped_scope]
    if as = @reflection.options[:as]
      # TODO: Need to add case for polymorphic :as option.
    else
      pattern = "#{@reflection.primary_key_name} = #{@owner.quoted_id}"
      replacement = "#{@reflection.primary_key_name} IN (#{@owner.group.quoted_ids})"
      conditions.sub!(pattern,replacement)
    end
  end
  conditions
end