Class: FindPointsWithMultipleTagsStrategy

Inherits:
QueryStrategy show all
Defined in:
lib/needle_in_a_haystack/strategies/find_points_with_multiple_tags_strategy.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, tags) ⇒ FindPointsWithMultipleTagsStrategy

Returns a new instance of FindPointsWithMultipleTagsStrategy.



2
3
4
5
6
# File 'lib/needle_in_a_haystack/strategies/find_points_with_multiple_tags_strategy.rb', line 2

def initialize(model, tags)
  super()
  @model = model
  @tags = tags
end

Instance Method Details

#executeObject



8
9
10
11
12
13
# File 'lib/needle_in_a_haystack/strategies/find_points_with_multiple_tags_strategy.rb', line 8

def execute
  @model.joins(:haystack_tags)
        .where(haystack_tags: { id: @tags.map(&:id) })
        .group("#{@model.table_name}.id")
        .having("COUNT(haystack_tags.id) = ?", @tags.size)
end