【发布时间】:2018-10-16 22:46:59
【问题描述】:
我有 2 个 activerecord 关系
class Proxy
# capacity integer
# country string
has_many :configs
end
class Config
belongs_to :proxy
# proxy_id
# port integer
end
我想在 activerecord 查询中查找特定国家/地区的所有代理,其中容量小于他的配置,并按配置计数器排序。
我的意思是我正在尝试做类似(伪 activrecord 示例)
Proxy.joins(:configs).where(country: country)
.where("capacity > ?", :configs.count)
.order_by(:configs.count)
我想也许我正纠结于我的问题,它有一个简单的解决方案。
提前致谢!
【问题讨论】:
标签: ruby-on-rails ruby activerecord