考虑一个简单的关联......
class Person
has_many :friends
end
class Friend
belongs_to :person
end
让所有在 ARel 和/或 meta_where 中没有朋友的人最干净的方法是什么?
那么 has_many :through 版本呢
class Person
has_many :contacts
has_many :friends, :through => :contacts, :uniq => true
end
class Friend
has_many :contacts
has_many :people, :through => :contacts, :uniq => true
end
class Contact
belongs_to :friend
belongs_to :person
end
我真的不想使用 counter_cache - 从我读过的内容来看,它不适用于 has_many :through
我不想提取所有 person.friends 记录并在 Ruby 中循环它们 - 我想要一个可以与 meta_search gem 一起使用的查询/范围
我不介意查询的性能成本
离实际 SQL 越远越好……