rails 模型: 类别有项目
尝试获取实际包含项目的类别列表。
类似于:
@categories = Category.where(category.items.count > 0).all
谢谢!
最佳答案
rails 3?
Category.joins(:items).select('distinct categories.*')
应该可以。
关于ruby-on-rails - rails : List of categories where related items count is greater than 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383253/