Class: FindPointsWithMultipleTagsStrategy
- Inherits:
-
QueryStrategy
- Object
- QueryStrategy
- FindPointsWithMultipleTagsStrategy
- Defined in:
- lib/needle_in_a_haystack/strategies/find_points_with_multiple_tags_strategy.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(model, tags) ⇒ FindPointsWithMultipleTagsStrategy
constructor
A new instance of FindPointsWithMultipleTagsStrategy.
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, ) super() @model = model @tags = end |
Instance Method Details
#execute ⇒ Object
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 |