0

我正在尝试一种有效的方法来搜索搜索结果。像这样的东西:

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 中的名称已编入索引。
  • 有大量的产品和产品参数,所以效率在这里很重要。
4

1 回答 1

0

您可以创建一个数据库视图,然后您可以像模型一样查询。这是一篇关于它的文章的链接。有很多关于该主题的资源也可能有所帮助:D Rails Database Views

于 2019-11-05T08:24:53.987 回答