I have a table that holds data received from a thirdparty via an api and has the default id field that rails adds upon running the migration. I also have a primary key which I receive the from the third party which I need to store and use in my business logic. Without doing the following, the relations from other models don’t work:
class ThirdPartyStuff < ActiveRecord::Base
set_primary_key :thirdpartysID
...
end
Is that ok to do? Any pit falls or problems that might arise?
You can only have a primary key per table (the pk can contain more that one field but still only one PK).
If you want a column to act like a PK: set it as
UNIQUEandNOT NULL. If you want to reference another table: create aForeign Key.