Thibaut Barrère
2006-Mar-12 22:02 UTC
[Rails] AR - Migrations - how to use a varchar as primary key instead of int ?
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060312/797bca4b/attachment.html
Corey Lawson
2006-Mar-13 07:36 UTC
[Rails] AR - Migrations - how to use a varchar as primary key instead of int ?
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. On 3/12/06, Thibaut Barr?re <thibaut.barrere@gmail.com> 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 ? > > Should I also specify something in the model class ? > > thanks! > > Thibaut > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Thibaut Barrère
2006-Mar-13 11:04 UTC
[Rails] AR - Migrations - how to use a varchar as primary key instead of int ?
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 ? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060313/6919c4f6/attachment.html
Anthony Green
2006-Mar-13 12:36 UTC
[Rails] Re: AR - Migrations - how to use a varchar as primary key in
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 -- Posted via http://www.ruby-forum.com/.
Briggs
2006-Mar-14 00:17 UTC
[Rails] Re: AR - Migrations - how to use a varchar as primary key instead of int ?
Thibaut Barr?re wrote:> Hican 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.> 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 > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Briggs
2006-Mar-14 00:30 UTC
[Rails] Re: AR - Migrations - how to use a varchar as primary key instead of int ?
Doh, I am sorry, I should have read that you mentioned Migrations. Sorry, nothing to see from me.> Thibaut Barr?re wrote: >> Hi > can you just call the primary_key() method in your model class (your > subclass of ActiveRecord::Base)?
Apparently Analagous Threads
- Setting up Ruby + RubyOnRails on the new intel mac (any feedback?)
- currency conversion webservice in a rails app?
- Rake: How to determine the Rails version?
- Is there anybody use radrails as the editor?
- Do you store the source of third-parties plugins you rely on in your own version control ?