views:

482

answers:

2

Hi I want to have custom ids for a table and not use the default auto_increment. Is that possible? I have turned :id => false and later on I create a t.column :id, :bigint But when I create a new record the id is set to NULL

Is there anyway to bypass this behaviour. I could set my primary key to a field uid (it is actually facebook id) but usually it breaks for me as relations usually look for the id field

A: 

I don't know where the problem is. Of course id is NULL when you disable auto_increment for the id column and don't insert an id value by hand.

Btw: You can define the foreign and primary keys for relations. It is no problem to use facebook_id as primary key.

Lennart
I insert by hand User.create(:id=>9459405) but it doesn t matter i ll stic to Rails autoincrement defaults as i had some problems in the past
PanosJee
+3  A: 

It's almost certainly going to be easier to use Rails' surrogate autoincrement ID as your primary ID.

There's no problem having a second unique column facebook_id and performing all your searches based on that field, but for the compatability reasons you mention (i.e. plugin authors making assumptions they shouldn't) I'd stick with Rails defaults as much as sensible. The performance issues relating to primary keys vs unique keys are minimal

Gareth