想要在Rails中查找没有相关记录的记录
考虑一个简单的关联......
class Person has_many :friendsendclass Friend belongs_to :personend
让所有在ARel和/或meta_where中没有朋友的人最简洁的方法是什么?
然后是一个has_many:通过版本
class Person has_many :contacts has_many :friends, :through => :contacts, :uniq => trueendclass Friend has_many :contacts has_many :people, :through => :contacts, :uniq => trueendclass Contact belongs_to :friend belongs_to :personend
我真的不想使用counter_cache - 而且我从我读过的内容中看起来并不适用于has_many:通过
我不想拉出所有的person.friends记录并在Ruby中循环它们 - 我希望有一个可以与meta_search gem一起使用的查询/范围
我不介意查询的性能成本
而离实际SQL越远越好......
Qyouu
胡子哥哥
凤凰求蛊
相关分类