自定义非自动递增的ActiveRecord" ID"列可能吗?

问题描述:

我希望能够使用自定义的ID(而不是自动递增默认的)为Rails模型。基本上,所有标识的iTunes商店的ID,这只是长整数。是否有可能关闭默认自动递增的ID,并要求之一进行设置?这些ID也将被用作其他模型外键。

I'd like to be able to use a custom id (instead of the auto-incrementing default ones) for a Rails model. Basically, all the ids will be iTunes store ids, which are just long integers. Is it possible to turn off the default auto-incrementing ids and require that one be set? These ids will also be used as foreign keys in other models.

事情是这样的:

create_table :blah, {:id => false} do |t|
  t.int :my_custom_int_id
end
execute "ALTER TABLE blah ADD PRIMARY KEY (my_custom_int_id);"