From a5fa8fde2549651f03431f32bd72dd63dcfa9ee3 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 16 Jan 2024 12:44:20 +0100 Subject: [PATCH] WIP --- activerecord/lib/active_record/relation.rb | 2 +- activerecord/lib/active_record/relation/delegation.rb | 3 +-- activerecord/test/models/author.rb | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 873b0e6498078..f4c2bbe317f93 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -1111,7 +1111,7 @@ def instantiate_records(rows, &block) def skip_query_cache_if_necessary(&block) if skip_query_cache_value - uncached(&block) + model.uncached(&block) else yield end diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index 6cb265447a2d8..984f6ca6ab643 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -100,8 +100,7 @@ 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, :unscoped, to: :klass + delegate :primary_key, :connection, :table_name, :transaction, :sanitize_sql_like, :unscoped, to: :klass # TODO: scoped delegate [:find_signed, :find_signed!, :delete, :find_by_token_for, :find_by_token_for!, :upsert_all, :insert_all, :insert_all!].each do |method| diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 61cb079579669..678dcb2a60547 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -209,10 +209,10 @@ def ratings has_many :posts_with_default_include, class_name: "PostWithDefaultInclude" has_many :comments_on_posts_with_default_include, through: :posts_with_default_include, source: :comments - has_many :posts_with_signature, ->(record) { where(arel_table[:title].matches("%by #{record.name.downcase}%")) }, class_name: "Post" - has_many :posts_mentioning_author, ->(record = nil) { where(arel_table[:body].matches("%#{record&.name&.downcase}%")) }, class_name: "Post" + has_many :posts_with_signature, ->(record) { where(model.arel_table[:title].matches("%by #{record.name.downcase}%")) }, class_name: "Post" + has_many :posts_mentioning_author, ->(record = nil) { where(model.arel_table[:body].matches("%#{record&.name&.downcase}%")) }, class_name: "Post" has_many :comments_on_posts_mentioning_author, through: :posts_mentioning_author, source: :comments - has_many :comments_mentioning_author, ->(record) { where(arel_table[:body].matches("%#{record.name.downcase}%")) }, through: :posts, source: :comments + has_many :comments_mentioning_author, ->(record) { where(model.arel_table[:body].matches("%#{record.name.downcase}%")) }, through: :posts, source: :comments has_one :recent_post, -> { order(id: :desc) }, class_name: "Post" has_one :recent_response, through: :recent_post, source: :comments