ruby-on-rails – ActiveRecord与ID数组连接
发布时间:2020-12-17 01:33:05 所属栏目:百科 来源:网络整理
导读:以下命令在拉出具有特定功能的所有样式时非常有用: 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) 有可能做同样的事情,但对于一系列功能?如: Style.joins(:style_features).where('style_features.feature_id= ?',[1,2,3]) 解决方法
你可以简单地做:
Style.joins(:style_features).where(style_features: { feature_id: [1,3] }) 此查询将让Rails根据您定义的DataBase Adapter处理SQL查询. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |