Skip to content

Commit

Permalink
Merge pull request #25972 from kamipo/backport_25146
Browse files Browse the repository at this point in the history
Backport #25146 to 5-0-stable
  • Loading branch information
rafaelfranca committed Jul 28, 2016
2 parents cbe752f + 0b5b069 commit cd167f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/table_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def associated_with?(association_name)
end

def associated_table(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 && table_name == arel_table.name
return self
Expand Down
18 changes: 18 additions & 0 deletions activerecord/test/cases/associations/has_one_associations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cd167f9

Please sign in to comment.