A fix for a bug that you can reproduce right now easily: visit the demo app (https://administrate-prototype.herokuapp.com/admin/customers), select any customer, edit, save, and the customer will lose their territory value.
This is a bug introduced with https://github.com/thoughtbot/administrate/pull/1633, where I failed to use associated_primary_key to refer to the key on the other side of a foreign key.
Specifically in our demo app, the Customer model belongs to Country . However instead of the conventional matching of Customer#country_id to Country#id, it should match Customer#country_code to Country#code. While foreign_key gives us country_code, we wrongly use primary_key for the counterpart. Instead we should use association_primary_key which gives us code.
Fixes https://github.com/thoughtbot/administrate/issues/2169