Module: GroupedScope::HasManyAssociation

Defined in:
lib/grouped_scope/has_many_association.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

[View source]

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

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

Instance Method Details

#construct_sql_with_group_scopeObject

[View source]

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

def construct_sql_with_group_scope
  if @reflection.options[:grouped_scope]
    # CHANGED [Rails 1.2.6] Account for quoted_table_name.
    table_name = @reflection.respond_to?(:quoted_table_name) ? @reflection.quoted_table_name : @reflection.klass.table_name
    if @reflection.options[:as]
      # TODO: Need to add case for polymorphic :as option.
    else
      @finder_sql = "#{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