File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -797,6 +797,8 @@ def derive_fk_query_constraints(foreign_key)
797
797
MSG
798
798
end
799
799
800
+ return foreign_key if primary_query_constraints . include? ( foreign_key )
801
+
800
802
first_key , last_key = primary_query_constraints
801
803
802
804
if first_key == owner_pk
Original file line number Diff line number Diff line change @@ -620,6 +620,14 @@ def test_association_primary_key_uses_explicit_primary_key_option_as_first_prior
620
620
assert_equal "id" , actual
621
621
end
622
622
623
+ def test_belongs_to_reflection_with_query_constraints_infers_correct_foreign_key
624
+ blog_foreign_key = Sharded ::Comment . reflect_on_association ( :blog ) . foreign_key
625
+ blog_post_foreign_key = Sharded ::Comment . reflect_on_association ( :blog_post ) . foreign_key
626
+
627
+ assert_equal "blog_id" , blog_foreign_key
628
+ assert_equal [ "blog_id" , "blog_post_id" ] , blog_post_foreign_key
629
+ end
630
+
623
631
private
624
632
def assert_reflection ( klass , association , options )
625
633
assert reflection = klass . reflect_on_association ( association )
You can’t perform that action at this time.
0 commit comments