Reputation: 309
I was told that I should always use integer for defining foreign keys in a Rails model. Is this true? Are there cases where using a string might be better?
Upvotes: 2
Views: 407
Reputation: 13181
Numeric IDs is the general convention, but strings can be used when it really makes sense. See those links for more information:
Database Design and the use of non-numeric Primary Keys
Strings as Primary Keys in SQL Database
http://databases.about.com/od/specificproducts/a/keys.htm
Upvotes: 1
Reputation: 14038
You don't have to, but it's the rails default and rails works best when you work with it. Your life will be easier if you use integers, but if you don't want to this question had some excellent discussion on the matter.
Upvotes: 1