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.
This commit is contained in:
John Hawthorn 2020-05-12 11:10:39 -07:00
parent 0dc3f5146d
commit 1b773bca5c
2 changed files with 6 additions and 1 deletions

View File

@ -199,7 +199,7 @@ module ActiveRecord
private
def singleton_method_added(name)
generate_relation_method(name) if Kernel.respond_to?(name)
generate_relation_method(name) if Kernel.respond_to?(name) && !ActiveRecord::Relation.method_defined?(name)
end
def valid_scope_name?(name)

View File

@ -10,9 +10,14 @@ class Reply < Topic
scope :ordered, -> { Reply.order(:id) }
# Method on Kernel
def self.open
approved
end
# Methods both on Kernel and Relation
def self.load(data:); end
def self.select(data:); end
end
class SillyReply < Topic