Merge pull request #39256 from jhawthorn/methods_on_kernel_and_relation

Avoid confliting Kernel-named scopes on Relation
This commit is contained in:
John Hawthorn 2020-05-12 12:03:34 -07:00 committed by GitHub
commit 243d891072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -199,7 +199,7 @@ module ActiveRecord
private private
def singleton_method_added(name) 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 end
def valid_scope_name?(name) def valid_scope_name?(name)

View File

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