mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #39210 from kamipo/fix_kernel_open
Eager generate relation methods if a method is on `Kernel`
This commit is contained in:
commit
ae46546ea3
4 changed files with 11 additions and 0 deletions
|
@ -198,6 +198,10 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
private
|
||||
def singleton_method_added(name)
|
||||
generate_relation_method(name) if Kernel.respond_to?(name)
|
||||
end
|
||||
|
||||
def valid_scope_name?(name)
|
||||
if respond_to?(name, true) && logger
|
||||
logger.warn "Creating scope :#{name}. " \
|
||||
|
|
|
@ -2119,6 +2119,8 @@ class RelationTest < ActiveRecord::TestCase
|
|||
sub_accounts = SubAccount.all
|
||||
assert_equal [accounts(:signals37)], sub_accounts.open
|
||||
assert_equal [accounts(:signals37)], sub_accounts.available
|
||||
|
||||
assert_equal [topics(:second)], topics(:first).open_replies
|
||||
end
|
||||
|
||||
def test_where_with_take_memoization
|
||||
|
|
|
@ -9,6 +9,10 @@ class Reply < Topic
|
|||
has_many :silly_unique_replies, dependent: :destroy, foreign_key: "parent_id"
|
||||
|
||||
scope :ordered, -> { Reply.order(:id) }
|
||||
|
||||
def self.open
|
||||
approved
|
||||
end
|
||||
end
|
||||
|
||||
class SillyReply < Topic
|
||||
|
|
|
@ -42,6 +42,7 @@ class Topic < ActiveRecord::Base
|
|||
|
||||
has_many :replies, dependent: :destroy, foreign_key: "parent_id", autosave: true
|
||||
has_many :approved_replies, -> { approved }, class_name: "Reply", foreign_key: "parent_id", counter_cache: "replies_count"
|
||||
has_many :open_replies, -> { open }, class_name: "Reply", foreign_key: "parent_id"
|
||||
|
||||
has_many :unique_replies, dependent: :destroy, foreign_key: "parent_id"
|
||||
has_many :silly_unique_replies, dependent: :destroy, foreign_key: "parent_id"
|
||||
|
|
Loading…
Reference in a new issue