Ruby-如何使用嵌套联接查找客户

Ruby-如何使用嵌套联接查找客户,ruby,postgresql,Ruby,Postgresql,我有以下关系: class Location < ApplicationRecord has_many :weddings class Wedding < ApplicationRecord has_many :wedding_memberships class WeddingMembership < ApplicationRecord belongs_to :wedding belongs_to :customer class Customer <

我有以下关系:

class Location < ApplicationRecord
  has_many :weddings

class Wedding < ApplicationRecord
  has_many :wedding_memberships

class WeddingMembership < ApplicationRecord
  belongs_to :wedding
  belongs_to :customer

class Customer < ApplicationRecord
  has_many :wedding_memberships
类位置
我想找到的是
位置
中的
客户
s,id:1


我的尝试
WeddingMembership.joins(:wedding).where(wedding:{location\u id:1})
给我带来了以下错误:
由PG::UndefinedTable引起:错误:表“wedding”的子句条目中缺少了

试试这一个,它是一个多重连接,在
location\u id上有一个where子句

Customer.joins(wedding_memberships: :wedding)
        .where(weddings: { location_id: 1 })
        .distinct

WeddingMembership.join(:wedding)。其中(weddings:{location\u id:1})
weddings
,您需要table@Ursus这确实有效,但是当我需要客户时,它会返回
婚礼会员资格
是的,我也去了。。但当我尝试这样做时,我得到了
ActiveRecord::ConfigurationError:无法将“客户”加入名为“婚礼”的协会;也许你拼错了?
你确定你试过使用我相同的
连接
子句吗?如果您的关联是正确的,那么这应该会起作用。我认为您错过了
加入
条款中的
婚礼成员资格
,我没有这样做
(婚礼成员资格::婚礼)
。。非常感谢!最后我可能错过了一个明显的