diff --git a/CHANGELOG.md b/CHANGELOG.md index e35697f..442985c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [Unreleased] +- AR 6.1: fix - FrozenError: can't modify frozen object: [] - Drop support for ActiveRecord older than 6.0. ## [1.4.4] - 2022-02-07 diff --git a/lib/baby_squeel/active_record/query_methods.rb b/lib/baby_squeel/active_record/query_methods.rb index 267f69e..7e2dcc2 100644 --- a/lib/baby_squeel/active_record/query_methods.rb +++ b/lib/baby_squeel/active_record/query_methods.rb @@ -64,7 +64,9 @@ def construct_join_dependency(associations, join_type) # https://github.com/rails/rails/commit/c0c53ee9d28134757cf1418521cb97c4a135f140 def select_association_list(*args) - args[0].extend(BabySqueel::ActiveRecord::QueryMethods::Injector6_1) + if args[0].any? { |join| join.is_a?(BabySqueel::Join) } + args[0].extend(BabySqueel::ActiveRecord::QueryMethods::Injector6_1) + end super *args end else diff --git a/spec/integration/__snapshots__/rails_integration_spec.yaml b/spec/integration/__snapshots__/rails_integration_spec.yaml index 13ae09d..fe8dfd4 100644 --- a/spec/integration/__snapshots__/rails_integration_spec.yaml +++ b/spec/integration/__snapshots__/rails_integration_spec.yaml @@ -5,3 +5,10 @@ test that plain rails still works joins and merge 1: SELECT "authors".* FROM "au test that plain rails still works left_joins 1: SELECT "posts".* FROM "posts" LEFT OUTER JOIN "posts" "parents_posts" ON "parents_posts"."id" = "posts"."parent_id" LEFT OUTER JOIN "authors" ON "authors"."id" = "posts"."author_id" +test that plain rails still works joins includes 1: SELECT "posts"."id" AS t0_r0, + "posts"."title" AS t0_r1, "posts"."author_id" AS t0_r2, "posts"."published_at" AS + t0_r3, "posts"."view_count" AS t0_r4, "posts"."parent_id" AS t0_r5, "posts"."created_at" + AS t0_r6, "posts"."updated_at" AS t0_r7, "authors"."id" AS t1_r0, "authors"."name" + AS t1_r1, "authors"."age" AS t1_r2, "authors"."ugly" AS t1_r3, "authors"."created_at" + AS t1_r4, "authors"."updated_at" AS t1_r5 FROM "posts" INNER JOIN "authors" ON "authors"."id" + = "posts"."author_id" diff --git a/spec/integration/rails_integration_spec.rb b/spec/integration/rails_integration_spec.rb index a6dd3dc..418c3d3 100644 --- a/spec/integration/rails_integration_spec.rb +++ b/spec/integration/rails_integration_spec.rb @@ -12,4 +12,10 @@ expect(relation).to match_sql_snapshot end + + it 'joins includes' do + relation = Post.joins(:author).includes(:author).to_sql + + expect(relation).to match_sql_snapshot + end end