【发布时间】:2012-09-17 22:44:15
【问题描述】:
试图找到相互关系,在朋友关系中,已经有朋友和inverse_friends。但是如何将它们结合起来得到共同的朋友呢? 似乎无法弄清楚我尝试了几个选项并在网上搜索了很长时间,只是没有看到它
has_many :friendships
has_many :friends, :through => :friendships
has_many :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id"
has_many :inverse_friends, :through => :inverse_friendships, :source => :user
如何获得
has_many :mutual_friends ?
【问题讨论】:
-
如果您发布了表定义,解决您的问题会更容易,这样我们就不必猜测您的架构。
标签: ruby-on-rails activerecord mutual-friendship