考虑这段代码:
# in Rails 6.1
def preload(resource, relations)
ActiveRecord::Associations::Preloader.new.preload(resource, relations)
end
Run Code Online (Sandbox Code Playgroud)
所以:我想改变它以与 Rails 7 兼容,所以我写了这个:
def preload(resource, relations)
ActiveRecord::Associations::Preloader.new(records: resource, associations: relations)
end
Run Code Online (Sandbox Code Playgroud)
我做对了吗?因为 .preload(resource,relations) 在 Rails 7 中不再存在。如果您有任何其他建议,我非常期待