From 189e3342988411a293b677d0e329d1d88ebd5cb4 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 22 Dec 2023 13:31:45 +0100 Subject: [PATCH] WIP --- .../lib/active_record/relation/delegation.rb | 12 +++++++++++- .../has_and_belongs_to_many_associations_test.rb | 8 ++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index fd22f1736bbe..5c502221a4fd 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -101,7 +101,17 @@ def #{method}(...) :to_sentence, :to_fs, :to_formatted_s, :as_json, :shuffle, :split, :slice, :index, :rindex, to: :records - delegate :primary_key, :connection, :table_name, :transaction, :arel_table, :uncached, :sanitize_sql_like, to: :klass + delegate :primary_key, :connection, :table_name, :transaction, :arel_table, :uncached, + :sanitize_sql_like, :unscoped, to: :klass + + # TODO: scoped delegate + [:find_signed, :find_signed!, :delete].each do |method| + module_eval <<-RUBY, __FILE__, __LINE__ + 1 + def #{method}(...) + scoping { klass.#{method}(...) } + end + RUBY + end module ClassSpecificRelation # :nodoc: extend ActiveSupport::Concern diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index af612bd794ae..acd721ddaeac 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -828,14 +828,14 @@ def test_caching_of_columns # clear cache possibly created by other tests Project.reset_column_information - assert_queries_count(include_schema: true) { david.projects.columns } - assert_no_queries { david.projects.columns } + assert_queries_count(include_schema: true) { Project.columns } + assert_no_queries { Project.columns } ## and again to verify that reset_column_information clears the cache correctly Project.reset_column_information - assert_queries_count(include_schema: true) { david.projects.columns } - assert_no_queries { david.projects.columns } + assert_queries_count(include_schema: true) { Project.columns } + assert_no_queries { Project.columns } end def test_attributes_are_being_set_when_initialized_from_habtm_association_with_where_clause