Ruby on rails Rails模型与的关联有很多,通过类名称和where子句

Ruby on rails Rails模型与的关联有很多,通过类名称和where子句,ruby-on-rails,model-associations,Ruby On Rails,Model Associations,正在寻找有关rails关联的一些帮助。我有三种型号。用户、与会者和会议,我希望返回一个基于角色(在与会者模型下)参加会议的用户。但是,我不知道如何使用where子句返回用户 我的代码当前返回与会者,然后我查找用户对象,但如果我能让它返回用户对象而不必在调用后查找它,我会喜欢它 class Meeting has_one :owner, -> { where role: 'owner' }, class_name: 'Attendee' has_one :mentor, ->

正在寻找有关rails关联的一些帮助。我有三种型号。用户、与会者和会议,我希望返回一个基于角色(在与会者模型下)参加会议的用户。但是,我不知道如何使用where子句返回用户

我的代码当前返回
与会者
,然后我查找
用户
对象,但如果我能让它返回
用户
对象而不必在调用后查找它,我会喜欢它

class Meeting

  has_one :owner, -> { where role: 'owner' }, class_name: 'Attendee'
  has_one :mentor, -> { where role: 'mentor' }, class_name: 'Attendee'
  has_many :mentees, -> { where role: 'mentee' }, class_name: 'Attendee'

end
我的其他联系如下

  has_many :users, through: :attendees
  has_many :attendees, dependent: :destroy

这可能吗?非常感谢您的任何意见

我不确定我是否正确理解了你。你试过这个吗?这是你需要的吗

class Meeting
  has_one :owner, -> { where role: 'owner' }, class_name: 'Attendee'
  has_one :mentor, -> { where role: 'mentor' }, class_name: 'Attendee'
  has_many :mentees, -> { where role: 'mentee' }, class_name: 'Attendee'

  has_one :owner_user, through: :owner, source: :user
  has_one :mentor_user, through: :mentor, source: :user
  has_many :mentees_users, through: :mentees, source: :user
end

谢谢Chumakoff,我不知道事情是这样的!它只是在每一行的末尾缺少一件事
source::user