1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix where with has_many through *belongs_to* association

Folloe up to 01cffc3789.
This commit is contained in:
Ryuta Kamizono 2020-11-22 11:53:47 +09:00
parent 371b480026
commit c966313634
3 changed files with 10 additions and 2 deletions

View file

@ -100,7 +100,7 @@ module ActiveRecord
end
elsif associated_table.through_association?
next associated_table.predicate_builder.expand_from_hash(
associated_table.join_foreign_key => value
associated_table.primary_key => value
)
end

View file

@ -10,6 +10,10 @@ module ActiveRecord
@reflection = reflection
end
def primary_key
klass&.primary_key
end
def type(column_name)
arel_table.type_for_attribute(column_name)
end

View file

@ -5,6 +5,8 @@ require "models/author"
require "models/binary"
require "models/cake_designer"
require "models/car"
require "models/category"
require "models/categorization"
require "models/chef"
require "models/post"
require "models/comment"
@ -18,7 +20,8 @@ require "support/stubs/strong_parameters"
module ActiveRecord
class WhereTest < ActiveRecord::TestCase
fixtures :posts, :comments, :edges, :authors, :author_addresses, :binaries, :essays, :cars, :treasures, :price_estimates, :topics
fixtures :authors, :author_addresses, :categories, :categorizations, :cars, :treasures, :price_estimates,
:binaries, :edges, :essays, :posts, :comments, :topics
def test_type_casting_nested_joins
comment = comments(:eager_other_comment1)
@ -27,6 +30,7 @@ module ActiveRecord
def test_where_with_through_association
assert_equal [authors(:david)], Author.joins(:comments).where(comments: comments(:greetings))
assert_equal [authors(:bob)], Author.joins(:categories).where(categories: categories(:technology))
end
def test_type_cast_is_not_evaluated_at_relation_build_time