如何使用ActiveRecord在Ruby on Rails中将ID数组与查询连接?
- 内容介绍
- 文章标签
- 相关推荐
本文共计176个文字,预计阅读时间需要1分钟。
以下是对原文的简化
使用以下命令可以拉取具有特定功能的对象样式:Style.joins(:style_features).where('style_features.feature_id=?', 1)这可能用于执行相同的事情,但针对系列功能?例如:Style.joins(:style_features).where('style_features.feature_id=?')
以下命令在拉出具有特定功能的所有样式时非常有用:Style.joins(:style_features).where('style_features.feature_id= ?', 1)
有可能做同样的事情,但对于一系列功能?如:
Style.joins(:style_features).where('style_features.feature_id= ?', [1, 2, 3]) 你可以简单地做:
Style.joins(:style_features).where(style_features: { feature_id: [1, 2, 3] })
此查询将让Rails根据您定义的DataBase Adapter处理SQL查询.
本文共计176个文字,预计阅读时间需要1分钟。
以下是对原文的简化
使用以下命令可以拉取具有特定功能的对象样式:Style.joins(:style_features).where('style_features.feature_id=?', 1)这可能用于执行相同的事情,但针对系列功能?例如:Style.joins(:style_features).where('style_features.feature_id=?')
以下命令在拉出具有特定功能的所有样式时非常有用:Style.joins(:style_features).where('style_features.feature_id= ?', 1)
有可能做同样的事情,但对于一系列功能?如:
Style.joins(:style_features).where('style_features.feature_id= ?', [1, 2, 3]) 你可以简单地做:
Style.joins(:style_features).where(style_features: { feature_id: [1, 2, 3] })
此查询将让Rails根据您定义的DataBase Adapter处理SQL查询.

