Hi
I’d like to have a varchar primary key named id instead of the default
int
id. Does anyone knows how to specify this from migrations ?
Should I also specify something in the model class ?
thanks!
Thibaut
Hi
I’d like to have a varchar primary key named id instead of the default
int
id. Does anyone knows how to specify this from migrations ?
Should I also specify something in the model class ?
thanks!
Thibaut
Ya probably just…do it. You probably also want some kind of
iterator/sequence/generator/trigger in place to supply new values
automatically on insert.
What you should probably also do is create a table that stores the
last value used, so as to avoid the “select max(id) from mytable…”
brute force logic as well as any transaction issues, things that
sequences/generators do for you already in a transaction-safe manner.
Hi!
well when I add a column under migration, the type can be either
:string,
:integer, or :primary_key. I can’t seem to find how to have it defined
as
both a :string and a :primary_key. Or should I add custom sql ?
Thibaut Barrère wrote:
Hi
I’d like to have a varchar primary key named id instead of the default
int
id. Does anyone knows how to specify this from migrations ?
The Agile book suggest setting up a two primary ids - the first a new
one : int auto incremented and a second one your legacy pk
_tony
Thibaut Barrère wrote:
Hi
can you just call the primary_key() method in your model class (your
subclass of ActiveRecord::Base)?
The RDocs:
primary_key()
Defines the primary key field ? can be overridden in subclasses.
Overwriting will negate any effect of the primary_key_prefix_type
setting, though.
Doh, I am sorry, I should have read that you mentioned Migrations.
Sorry, nothing to see from me.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs