second_level_cache icon indicating copy to clipboard operation
second_level_cache copied to clipboard

Rails 8 support?

Open KoellM opened this issue 1 year ago • 2 comments

升级到 Rails 8 之后出现错误

/home/deploy1/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/second_level_cache-2.7.1/lib/second_level_cache/active_record/belongs_to_association.rb:7:in `find_target': wrong number of arguments (given 1, expected 0) (ArgumentError)
        from /home/deploy1/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/activerecord-8.0.0/lib/active_record/associations/association.rb:190:in `load_target'
        from /home/deploy1/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/activerecord-8.0.0/lib/active_record/associations/association.rb:76:in `reload'
        from /home/deploy1/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/activerecord-8.0.0/lib/active_record/associations/singular_association.rb:11:in `reader'
        from /home/deploy1/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/activerecord-8.0.0/lib/active_record/associations/builder/association.rb:105:in `xml'

看起来是因为 Rails 8 新的异步关联加载 API https://github.com/rails/rails/commit/fe92250a5c6182af0faec32c9518df48bcae51fd#diff-cac8ca279408e7447fa1f97443ec4c548a42a115c70349f7fa5e8ade10198a1cR240

KoellM avatar Nov 18 '24 02:11 KoellM

升级到 Rails 8.0.1后,我的也崩了。。。同样的错误

wrong number of arguments (given 1, expected 0)

clwy-cn avatar Dec 31 '24 14:12 clwy-cn

The fix is to add (async: false) to BelongsToAssociation and HasOneAssociation's method signatures. I don't have time to submit a PR, but I hope that helps.

bombino avatar Oct 14 '25 16:10 bombino