ArgumentError: The association scope 'children' is instance dependent (the scope block takes an argument). Preloading instance dependent scopes is not supported.
def check_preloadable!
return unless scope
if scope.arity > 0
raise ArgumentError, <<-MSG.squish
The association scope '#{name}' is instance dependent (the scope
block takes an argument). Preloading instance dependent scopes is
not supported.
MSG
end
end
...
这个是源码
需求是一张表通过 parent_id 关联自己 (has_many: children),但是还要加一个条件
class Cm::ProductCategory < ApplicationRecord
has_many :children, ->(p) {where(version_id: p.version_id)}, class_name: 'Cm::ProductCategory', primary_key: :product_category_id, foreign_key: :parent_id
...
这样写,includes 就报错