簡體   English   中英

蘭薩克搜索有很多通過

[英]Ransack search has many through

我有一個Profile模型:

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

我試圖在Profile索引中使用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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM