[英]Ransack search has many through
I have a Profile model: 我有一个Profile模型:
has_one :job_preference, inverse_of: :profile, dependent: :destroy
accepts_nested_attributes_for :job_preference, reject_if: :all_blank, allow_destroy: true
Job Preference model: 工作偏好模型:
belongs_to :profile
has_many :job_preferences_wanted_locations
has_many :wanted_locations, through: :job_preferences_wanted_locations, dependent: :destroy
Job Preference Wanted location model: 想要的工作偏好位置模型:
class JobPreferencesWantedLocation < ApplicationRecord
belongs_to :job_preference
belongs_to :wanted_location
accepts_nested_attributes_for :wanted_location
end
Wanted locations model: 所需地点模型:
class WantedLocation < ApplicationRecord
has_many :job_preferences_wanted_locations
has_many :job_preferences, through: :job_preferences_wanted_locations, dependent: :destroy
end
Im trying to use Ransack gem in the Profile index to make a query on wanted locations. 我试图在Profile索引中使用Ransack gem来查询所需位置。
I can access these wanted locations like this: 我可以像这样访问这些所需的位置:
profile.job_preference.wanted_locations.each do |n|
print n.name
end
I have read through the Ransack doc and tried variations of: 我已经阅读了Ransack文档,并尝试了以下方法的变体:
job_preference_wanted_location_name_cont
but this doesnot seem to work. 但这似乎不起作用。
try with 尝试
job_preferences_job_preferences_wanted_locations_wanted_location_name_cont
from profile, to associative (job preference - wanted location), to wanted location itself and the name attribute. 从个人资料到关联(工作偏好-所需位置),再到所需位置本身和名称属性。
The thing is that if I don't remember bad, ransack doesn't works directly with through associations. 关键是,如果我不记得不好的话,则不能通过关联直接使用ransack。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.