Fix for alternative primary keys

Primary keys might be something other than id.