0

authentications有很多用作primary_key和groupsforeign_key ,没问题。uidorganizer_id

uid在属性范围内是唯一的provider。我想确保我的关联只获取groupswhere authentication.provider == 'meetup'。我试过了:

has_many :groups, :primary_key => "uid", :foreign_key => "organizer_id", :conditions => {:provider => "meetup"}

但这只是试图找到groups所有provider == "meetup"

如何在主表上指定条件authentications

4

1 回答 1

0

尝试:

has_many :groups, :primary_key => "uid", :foreign_key => "organizer_id", :include => :authentication, :conditions => {:authentication => {:provider => "meetup"}}

更新:

如果 Group belongs_to身份验证使用“organizer_id”作为 foreign_key,那么只需:

Group.includes(:authentication).where(:authentication => {:provider => "meetup"})
于 2012-12-26T16:57:02.323 回答