提交 0a571e4a 编写于 作者: S Sean Griffin

Merge pull request #25146 from maclover7/fix-25128

Fix `has_one` `enum` `where` queries
......@@ -44,7 +44,8 @@ def associated_with?(association_name)
def associated_table(table_name)
return self if table_name == arel_table.name
association = klass._reflect_on_association(table_name)
association = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.singularize)
if association && !association.polymorphic?
association_klass = association.klass
arel_table = association_klass.arel_table.alias(table_name)
......
......@@ -659,4 +659,22 @@ def test_association_force_reload_with_only_true_is_deprecated
assert_deprecated { firm.account(true) }
end
class SpecialBook < ActiveRecord::Base
self.table_name = 'books'
belongs_to :author, class_name: 'SpecialAuthor'
end
class SpecialAuthor < ActiveRecord::Base
self.table_name = 'authors'
has_one :book, class_name: 'SpecialBook', foreign_key: 'author_id'
end
def test_assocation_enum_works_properly
author = SpecialAuthor.create!(name: 'Test')
book = SpecialBook.create!(status: 'published')
author.book = book
refute_equal 0, SpecialAuthor.joins(:book).where(books: { status: 'published' } ).count
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册