Class: NumberedRelationships::HasAndBelongsToManyConstructor
- Inherits:
-
Constructor
- Object
- Constructor
- NumberedRelationships::HasAndBelongsToManyConstructor
show all
- Defined in:
- lib/numbered_relationships/has_and_belongs_to_many.rb
Instance Method Summary
collapse
Methods inherited from Constructor
#initialize
Instance Method Details
#construct ⇒ Object
5
6
7
8
9
|
# File 'lib/numbered_relationships/has_and_belongs_to_many.rb', line 5
def construct
super
return construct_habtm_with_join_table if join_table
construct_habtm_without_join_table
end
|
#construct_habtm_with_join_table ⇒ Object
11
12
13
14
15
|
# File 'lib/numbered_relationships/has_and_belongs_to_many.rb', line 11
def construct_habtm_with_join_table
@klass.joins(association)
.group("#{table}.id")
.having("count(#{join_table}.#{foreign_key}) #{@operator} #{@n}")
end
|
#construct_habtm_without_join_table ⇒ Object
17
18
19
20
21
|
# File 'lib/numbered_relationships/has_and_belongs_to_many.rb', line 17
def construct_habtm_without_join_table
@klass.joins(association)
.group("#{table}.id")
.having("count(#{foreign_key}) #{@operator} #{@n}")
end
|