【发布时间】:2017-04-21 11:24:59
【问题描述】:
一直在到处寻找这个问题的答案。
has_one :region_location, ->(location) { where("region_locations.site_id = ?", location.current_site.id) if location.current_site }
此代码在我的开发环境中生成以下异常。
“关联范围‘region_location’是实例相关的( 范围块接受一个参数)。预加载实例相关范围 不支持。”
这似乎在 Rails 4 中是可能的,但在 5 中是不可能的 (Rails has_many with dynamic conditions)?任何建议将不胜感激。我曾考虑将其设为实例方法,但我也使用下面的关联。
has_one :region, :through => :region_location
【问题讨论】:
标签: ruby postgresql activerecord ruby-on-rails-5 has-many