作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
technology_id
。它是通过一个错误实现的。查询:
Vendor.where(vendors: {company: nil}).joins(technologies_vendors: {technology_id: "Technology.select(:technology_id).where(url: 'ios',is_verified: true)"})
错误:
ActiveRecord::ConfigurationError: Association named 'technology_id' was not found on TechnologiesVendor; perhaps you misspelled it?
最佳答案
我假设您已经设置了三个具有以下关系的模型:
Vendor has_many technologies_vendors
Technology has_many technologies_vendors
TechnologiesVendor belongs_to vendor
TechnologiesVendor belongs_to technology
您的条件是:
vendors should have 'nil' company
technologies should be verified and have 'ios' url
在这种情况下,这就是您想要的:
Vendor.
joins(technologies_vendors: :technology).
where({
vendors: {company: nil},
technologies: {url: 'ios', is_verified: true}
})
但是您也可以非常轻松地使用 merge
方法。
Vendor.
joins(technologies_vendors: :technology).
where(vendors: {company: nil}).
merge( Technology.where(technologies: {url: 'ios', is_verified: true}) )
但是,在这两种情况下,您都必须消除或稍微修改第二个查询。
关于mysql - 如何将查询直接传递给where条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28107898/
我是一名优秀的程序员,十分优秀!