gocardless / statesman

A statesmanlike state machine library.
https://gocardless.com/blog/statesman/
MIT License
1.78k stars 163 forks source link

Support relationships that doesn't use `id` as a Primary Key #422

Closed emancu closed 3 years ago

emancu commented 3 years ago

The convention of naming the Primary Key of a table as id is widespread on Rails applications and very useful. However, exceptions are also supported and widespread in Rails projects.

If we decide to model an entity with a primary key named external_id instead of just id, the methods provided by Statesman::Adapters::ActiveRecordQueries stop working as expected.

Even worse, if the model has the column id and external_id it will use the id even when this column is not a primary key, which leads to a problem because the query result will be incorrect but it won't fail as an error.