composite-primary-keys / composite_primary_keys

Composite Primary Keys support for Active Record
1.03k stars 350 forks source link

fix scoped associations #561

Closed ryantm closed 3 years ago

ryantm commented 3 years ago

Continuation of #560.

There is an SQL generation problem where a scoped association with composite primary keys gets generated with SQL like:

FROM `table1` INNER JOIN `table2` ON  AND

ON and AND are not supposed to be next to one another.

This adds a test to uncover the issue, and then fixes it with a patch.

The problem seems to be that append_constraints assumes that right.expr is non-empty, but in the case of CPK it is sometimes empty, presumably because id constraints have been removed.

Tests passing here: https://github.com/ryantm/composite_primary_keys/pull/2/checks

cfis commented 3 years ago

Thanks!