考虑一个简单的关联..。
class Person
has_many :friends
end
class Friend
belongs_to :person
end
要让所有在ARel和/或meta_where上没有朋友的人都加入进来,最干净的方法是什么?
那么has_many :直通版本呢?
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:
我不想提取所有的person.friends记录,然后在Ruby语言中遍历它们--我希望有一个可以在meta_search gem中使用的查询/范围
我不关心查询的性能成本
离实际的SQL越远越好。
https://stackoverflow.com/questions/5319400
复制相似问题