考虑一个简单的关联……
class Person
has_many :friends
end
class Friend
belongs_to :person
end
让所有在rel和/或meta_where中没有朋友的人获得朋友的最干净的方法是什么?
然后是has_many:through version
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越远越好……