我正在尝试一种有效的方法来搜索搜索结果。像这样的东西:
search_results = Product.joins(:product_params).where(product_params: {name: name_a, value: value_a})
# do something to search_results to make it where I can further filter the results based on product_params
search_results = search_results.joins(:product_params).where(product_params: {name: name_b, value: value_b})
- ProductParam 和 Product 通过 belongs_to / has_many 关联。
- product_params 中的名称已编入索引。
- 有大量的产品和产品参数,所以效率在这里很重要。