mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #29601 from kamipo/fix_eager_loading_to_respect_store_full_sti_class
Fix eager loading to respect `store_full_sti_class` setting
This commit is contained in:
commit
316e3c2ff1
3 changed files with 22 additions and 11 deletions
|
@ -1,3 +1,7 @@
|
|||
* Fix eager loading to respect `store_full_sti_class` setting.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
||||
* Query cache was unavailable when entering the ActiveRecord::Base.cache block
|
||||
without being connected.
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
if type
|
||||
klass_scope.where!(type => foreign_klass.base_class.name)
|
||||
klass_scope.where!(type => foreign_klass.base_class.sti_name)
|
||||
end
|
||||
|
||||
scope_chain_items.inject(klass_scope, &:merge!)
|
||||
|
|
|
@ -11,25 +11,32 @@ end
|
|||
|
||||
class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase
|
||||
def setup
|
||||
generate_test_objects
|
||||
end
|
||||
|
||||
def generate_test_objects
|
||||
post = Namespaced::Post.create(title: "Great stuff", body: "This is not", author_id: 1)
|
||||
Tagging.create(taggable: post)
|
||||
@tagging = Tagging.create(taggable: post)
|
||||
@old = ActiveRecord::Base.store_full_sti_class
|
||||
end
|
||||
|
||||
def test_class_names
|
||||
old = ActiveRecord::Base.store_full_sti_class
|
||||
def teardown
|
||||
ActiveRecord::Base.store_full_sti_class = @old
|
||||
end
|
||||
|
||||
def test_class_names_with_includes
|
||||
ActiveRecord::Base.store_full_sti_class = false
|
||||
post = Namespaced::Post.includes(:tagging).find_by_title("Great stuff")
|
||||
assert_nil post.tagging
|
||||
|
||||
ActiveRecord::Base.store_full_sti_class = true
|
||||
post = Namespaced::Post.includes(:tagging).find_by_title("Great stuff")
|
||||
assert_instance_of Tagging, post.tagging
|
||||
ensure
|
||||
ActiveRecord::Base.store_full_sti_class = old
|
||||
assert_equal @tagging, post.tagging
|
||||
end
|
||||
|
||||
def test_class_names_with_eager_load
|
||||
ActiveRecord::Base.store_full_sti_class = false
|
||||
post = Namespaced::Post.eager_load(:tagging).find_by_title("Great stuff")
|
||||
assert_nil post.tagging
|
||||
|
||||
ActiveRecord::Base.store_full_sti_class = true
|
||||
post = Namespaced::Post.eager_load(:tagging).find_by_title("Great stuff")
|
||||
assert_equal @tagging, post.tagging
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue