Fix #3890. (Calling proxy_association in scope chain.)
This commit is contained in:
parent
ebd71fd0e3
commit
5da90b3483
|
@ -41,8 +41,7 @@ module ActiveRecord
|
|||
delegate :group, :order, :limit, :joins, :where, :preload, :eager_load, :includes, :from,
|
||||
:lock, :readonly, :having, :pluck, :to => :scoped
|
||||
|
||||
delegate :target, :load_target, :loaded?, :scoped,
|
||||
:to => :@association
|
||||
delegate :target, :load_target, :loaded?, :to => :@association
|
||||
|
||||
delegate :select, :find, :first, :last,
|
||||
:build, :create, :create!,
|
||||
|
@ -62,6 +61,13 @@ module ActiveRecord
|
|||
@association
|
||||
end
|
||||
|
||||
def scoped
|
||||
association = @association
|
||||
association.scoped.extending do
|
||||
define_method(:proxy_association) { association }
|
||||
end
|
||||
end
|
||||
|
||||
def respond_to?(name, include_private = false)
|
||||
super ||
|
||||
(load_target && target.respond_to?(name, include_private)) ||
|
||||
|
|
|
@ -71,6 +71,12 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
|
|||
assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', extension_name(MyApplication::Business::Developer)
|
||||
end
|
||||
|
||||
def test_proxy_association_after_scoped
|
||||
post = posts(:welcome)
|
||||
assert_equal post.association(:comments), post.comments.the_association
|
||||
assert_equal post.association(:comments), post.comments.scoped.the_association
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def extension_name(model)
|
||||
|
|
|
@ -44,6 +44,10 @@ class Post < ActiveRecord::Base
|
|||
def newest
|
||||
created.last
|
||||
end
|
||||
|
||||
def the_association
|
||||
proxy_association
|
||||
end
|
||||
end
|
||||
|
||||
has_many :author_favorites, :through => :author
|
||||
|
@ -185,4 +189,4 @@ end
|
|||
class SpecialPostWithDefaultScope < ActiveRecord::Base
|
||||
self.table_name = 'posts'
|
||||
default_scope where(:id => [1, 5,6])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue