Skip to content

Commit 1b773bc

Browse files
committed
Avoid confliting Kernel-named scopes on Relation
A previous change made singleton methods eagerly define their relation methods if it shared a name with a method on Kernel. This caused issues with a few methods which were both defined on Kernel and on AcitveRecord::Relation. This commit avoids defining the method if it exists on AR::Relation.
1 parent 0dc3f51 commit 1b773bc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

activerecord/lib/active_record/scoping/named.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def scope(name, body, &block)
199199

200200
private
201201
def singleton_method_added(name)
202-
generate_relation_method(name) if Kernel.respond_to?(name)
202+
generate_relation_method(name) if Kernel.respond_to?(name) && !ActiveRecord::Relation.method_defined?(name)
203203
end
204204

205205
def valid_scope_name?(name)

activerecord/test/models/reply.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ class Reply < Topic
1010

1111
scope :ordered, -> { Reply.order(:id) }
1212

13+
# Method on Kernel
1314
def self.open
1415
approved
1516
end
17+
18+
# Methods both on Kernel and Relation
19+
def self.load(data:); end
20+
def self.select(data:); end
1621
end
1722

1823
class SillyReply < Topic

0 commit comments

Comments
 (0)