1

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?

Keeto
  • 4,074
  • 9
  • 35
  • 58

2 Answers2

1

I think its possible, but i would just add another column into your table (in the migration file) with the facebook id.

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