Rails 3 habtm 具有多个条目的过滤
我有一个产品模型和一个产品类别模型。它们之间有一个习惯。
我有“男士”和“牛仔裤”等类别,我想过滤这些类别。对男士进行过滤是没有问题的,但我需要过滤多个参数(男士和牛仔裤)。我尝试了一些变化,但我坚持这个。
这就是我到目前为止所拥有的..
Product.joins(:product_categories).where(['product_categories.id = 5 and product_categories.id = 6'])
感谢您的时间!
i have a product model and a product category model. and theres a habtm between those.
i have categories like 'men' and 'jeans' and i would like to filter these. to do a filter on men is no problem but i need to filter multiple parameters (men and jeans). i tried some variations but i'm stuck on this.
this is what i have so far..
Product.joins(:product_categories).where(['product_categories.id = 5 and product_categories.id = 6'])
thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样编写并传递您要过滤的 id 数组怎么样?
How about writting it like this and passing array of ids you're looking to filter by?
这是选择 men AND jeans 而不是 men OR jeans 的解决方案:
this is the solution which selects men AND jeans and not men OR jeans: