Can a ‘:primary_key’ to store strings or has to be integers?
t.primary_key :text_code
Can a ‘:primary_key’ to store strings or has to be integers?
t.primary_key :text_code
From a databases perspective, a string could easily be a primary key.
What
are you looking at acheiving, could you do it using
validates_uniquness_of
:xyz ?
Cheers,
James
James Brooks ha escrito:
From a databases perspective, a string could easily be a primary key. What
are you looking at acheiving, could you do it using validates_uniquness_of
:xyz ?
No, I need a string as primary key. I hope to have not any problem.
Thanks
In PSQL isn’t showed the primary key. I’m supposed that you have to
exec the sql yourself to add the primary key constraint.
Conclussion: it’s better don’t go against rails’ standard practices.
Solved!
Primary key for a string field of until 3 characters:
create_table :cars, :id => false, :primary_key => :alpha_code do |t|
t.string :alpha_code, :limit => 3
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