Skip to content

Commit 7186ceb

Browse files
authored
Merge pull request rails#52449 from jhawthorn/avoid_generated_method_name
Avoid eagerly generating Module methods on ActiveRecord::Relation delegation
2 parents ac1d768 + 66e25af commit 7186ceb

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

activerecord/lib/active_record/relation/delegation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def #{method}(...)
103103
:to_sentence, :to_fs, :to_formatted_s, :as_json,
104104
:shuffle, :split, :slice, :index, :rindex, to: :records
105105

106-
delegate :primary_key, :with_connection, :connection, :table_name, :transaction, :sanitize_sql_like, :unscoped, to: :model
106+
delegate :primary_key, :with_connection, :connection, :table_name, :transaction, :sanitize_sql_like, :unscoped, :name, to: :model
107107

108108
module ClassSpecificRelation # :nodoc:
109109
extend ActiveSupport::Concern

activerecord/lib/active_record/scoping/named.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ def scope(name, body, &block)
190190

191191
private
192192
def singleton_method_added(name)
193-
generate_relation_method(name) if Kernel.respond_to?(name) && !ActiveRecord::Relation.method_defined?(name)
193+
# Most Kernel extends are both singleton and instance methods so
194+
# respond_to is a fast check, but we don't want to define methods
195+
# only on the module (ex. Module#name)
196+
generate_relation_method(name) if Kernel.respond_to?(name) && (Kernel.method_defined?(name) || Kernel.private_method_defined?(name)) && !ActiveRecord::Relation.method_defined?(name)
194197
end
195198
end
196199
end

0 commit comments

Comments
 (0)