Ransack搜索有很多通过

Ransack search has many through

我有个人资料模型:

has_one :job_preference, inverse_of: :profile, dependent: :destroy
accepts_nested_attributes_for :job_preference, reject_if: :all_blank, allow_destroy: true

工作偏好模型:

belongs_to :profile
has_many :job_preferences_wanted_locations
has_many :wanted_locations, through: :job_preferences_wanted_locations, dependent: :destroy

求职地点模型:

class JobPreferencesWantedLocation < ApplicationRecord
  belongs_to :job_preference
  belongs_to :wanted_location

  accepts_nested_attributes_for :wanted_location
end

想要的位置模型:

class WantedLocation < ApplicationRecord
    has_many :job_preferences_wanted_locations
    has_many :job_preferences, through: :job_preferences_wanted_locations, dependent: :destroy
end

我正在尝试使用配置文件索引中的 Ransack gem 来查询所需位置。

我可以像这样访问这些想要的位置:

profile.job_preference.wanted_locations.each do |n|
    print n.name  
end

我已通读 Ransack 文档并尝试了以下变体:

job_preference_wanted_location_name_cont

但这似乎不起作用。

试试

job_preferences_job_preferences_wanted_locations_wanted_location_name_cont

从个人资料,到联想(工作偏好 - 想要的位置),到想要的位置本身和名称属性。

问题是,如果我记错了,ransack 不会直接通过关联工作。