diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-01-07 17:30:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-07 17:30:34 -0500 |
commit | 11a50f48113df300f3225e4963aeb1030ec6ad35 (patch) | |
tree | a83fb72f41fea92ec9e58fb242c966b0342219dd | |
parent | 7b13236818ffb26e94d72885e75966efffd71659 (diff) | |
parent | c322b7c2b1ace59921e0613151b26c8256e62a82 (diff) | |
download | rails-11a50f48113df300f3225e4963aeb1030ec6ad35.tar.gz rails-11a50f48113df300f3225e4963aeb1030ec6ad35.tar.bz2 rails-11a50f48113df300f3225e4963aeb1030ec6ad35.zip |
Merge pull request #27598 from NickLaMuro/fix-deep-nesting-where-clauses-with-joins
Fix bug with symbolized keys in .where with nested join
-rw-r--r-- | activerecord/lib/active_record/table_metadata.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_one_associations_test.rb | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/table_metadata.rb b/activerecord/lib/active_record/table_metadata.rb index b618e5cfcd..71efc1829a 100644 --- a/activerecord/lib/active_record/table_metadata.rb +++ b/activerecord/lib/active_record/table_metadata.rb @@ -44,7 +44,7 @@ module ActiveRecord end def associated_table(table_name) - association = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.singularize) + association = klass._reflect_on_association(table_name) || klass._reflect_on_association(table_name.to_s.singularize) if !association && table_name == arel_table.name return self diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index ed22a9802f..aa910ba409 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -648,6 +648,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase class SpecialBook < ActiveRecord::Base self.table_name = "books" belongs_to :author, class_name: "SpecialAuthor" + has_one :subscription, class_name: "SpecialSupscription", foreign_key: "subscriber_id" end class SpecialAuthor < ActiveRecord::Base @@ -655,6 +656,11 @@ class HasOneAssociationsTest < ActiveRecord::TestCase has_one :book, class_name: "SpecialBook", foreign_key: "author_id" end + class SpecialSupscription < ActiveRecord::Base + self.table_name = "subscriptions" + belongs_to :book, class_name: "SpecialBook" + end + def test_assocation_enum_works_properly author = SpecialAuthor.create!(name: "Test") book = SpecialBook.create!(status: "published") @@ -662,4 +668,15 @@ class HasOneAssociationsTest < ActiveRecord::TestCase refute_equal 0, SpecialAuthor.joins(:book).where(books: { status: "published" }).count end + + def test_assocation_enum_works_properly_with_nested_join + author = SpecialAuthor.create!(name: "Test") + book = SpecialBook.create!(status: "published") + author.book = book + + where_clause = { books: { subscriptions: { subscriber_id: nil } } } + assert_nothing_raised do + SpecialAuthor.joins(book: :subscription).where.not(where_clause) + end + end end |