Rails handle table id's automatically, in an incremental way. What if I want to stop this incremental behavior? I am actually building a website that uses the FB API and I d like to set the user id to be the facebook id. I am new to rails, so is that possible?
Asked
Active
Viewed 158 times
1
-
[answered here](http://stackoverflow.com/questions/969427/ruby-on-rails-custom-id) – PSorey Oct 20 '11 at 18:55
2 Answers
1
I think its possible, but i would just add another column into your table (in the migration file) with the facebook id.

Sebastian Oberste-Vorth
- 979
- 15
- 31
0
In your migrations file, have something like this:
create_table :users, {:id => false} do |t|
t.integer :facebook_id
end
and in your model class
Rails 3
class User < ActiveRecord::Base
set_primary_key :facebook_id
end
Rails 4
class User < ActiveRecord::Base
self.primary_key = :facebook_id
end

gregoltsov
- 2,269
- 1
- 22
- 37