Class: NumberedRelationships::HasManyConstructor

Inherits:
Constructor
  • Object
show all
Defined in:
lib/numbered_relationships/has_many.rb

Instance Method Summary collapse

Methods inherited from Constructor

#initialize

Constructor Details

This class inherits a constructor from NumberedRelationships::Constructor

Instance Method Details

#constructObject



5
6
7
8
9
# File 'lib/numbered_relationships/has_many.rb', line 5

def construct
  super
  return construct_has_many_filtered unless @filters.empty?
  construct_has_many_unfiltered
end

#construct_has_many_filteredObject



16
17
18
19
20
21
# File 'lib/numbered_relationships/has_many.rb', line 16

def construct_has_many_filtered
  @klass.joins(association)
        .merge(eval("#{constantize_klass}.#{chain_symbols(@filters)}"))
        .group("#{table}.id")
        .having("count(#{association.to_s}.id) #{@operator} #{@n}")
end

#construct_has_many_unfilteredObject



10
11
12
13
14
# File 'lib/numbered_relationships/has_many.rb', line 10

def construct_has_many_unfiltered
  @klass.joins(association)
        .group("#{table}.id")
        .having("count(#{association.to_s}.id) #{@operator} #{@n}")
end