3
一直在尋找答案。Rails 5動態條件has_many
has_one :region_location, ->(location) { where("region_locations.site_id = ?", location.current_site.id) if location.current_site }
此代碼在我的開發環境中生成以下異常。
「的關聯範圍‘region_location’是實例依賴性的(在 範圍塊需要一個參數)。預壓實例依賴範圍不支持 」。
看來喜歡的事,在軌道4,5是可能的,但不是在5(Rails has_many with dynamic conditions)?任何建議將不勝感激。我想讓它成爲實例方法,但我也使用下面的關聯。
has_one :region, :through => :region_location
感謝。這似乎工作。肯定會減慢速度,但因爲太陽黑子solr我不能做:包括用這種方式定義的關係。 –
@BenScheib嗯,這有點困難。可能需要挖掘rails源以找到解決方案 – engineersmnky