diff --git a/app/models/pool.rb b/app/models/pool.rb index c00dc2523..61a557521 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -51,7 +51,8 @@ class Pool < ApplicationRecord def post_tags_match(query) posts = Post.tag_match(query).select(:id).reorder(nil) - joins("CROSS JOIN unnest(post_ids) AS post_id").group(:id).where("post_id IN (?)", posts) + pools = Pool.joins("CROSS JOIN unnest(post_ids) AS post_id").group(:id).where("post_id IN (?)", posts) + where(id: pools) end def default_order diff --git a/test/unit/pool_test.rb b/test/unit/pool_test.rb index 5710439fa..b5f5a2cac 100644 --- a/test/unit/pool_test.rb +++ b/test/unit/pool_test.rb @@ -87,6 +87,10 @@ class PoolTest < ActiveSupport::TestCase assert_equal([@pool2.id, @pool1.id], Pool.search(post_tags_match: "bkub").pluck(:id)) assert_equal([@pool2.id, @pool1.id], Pool.search(post_tags_match: "fumimi").pluck(:id)) assert_equal([@pool2.id], Pool.search(post_tags_match: "bkub fumimi").pluck(:id)) + + assert_equal(2, Pool.search(post_tags_match: "bkub").count) + assert_equal(2, Pool.search(post_tags_match: "fumimi").count) + assert_equal(1, Pool.search(post_tags_match: "bkub fumimi").count) end end