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 @@ -804,6 +804,8 @@ def derive_fk_query_constraints(foreign_key)
804
804
MSG
805
805
end
806
806
807
+ return foreign_key if primary_query_constraints . include? ( foreign_key )
808
+
807
809
first_key , last_key = primary_query_constraints
808
810
809
811
if first_key == owner_pk
Original file line number Diff line number Diff line change @@ -653,6 +653,14 @@ def test_association_primary_key_uses_explicit_primary_key_option_as_first_prior
653
653
assert_equal "id" , actual
654
654
end
655
655
656
+ def test_belongs_to_reflection_with_query_constraints_infers_correct_foreign_key
657
+ blog_foreign_key = Sharded ::Comment . reflect_on_association ( :blog ) . foreign_key
658
+ blog_post_foreign_key = Sharded ::Comment . reflect_on_association ( :blog_post ) . foreign_key
659
+
660
+ assert_equal "blog_id" , blog_foreign_key
661
+ assert_equal [ "blog_id" , "blog_post_id" ] , blog_post_foreign_key
662
+ end
663
+
656
664
private
657
665
def assert_reflection ( klass , association , options )
658
666
assert reflection = klass . reflect_on_association ( association )
You can’t perform that action at this time.
0 commit comments