Hi, I just want to know if rails regard primary key (id) as integer, or can I have primary key as varchar? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
By default, it looks for a id field of int, however, you can let ActiveRecord know which field you want as the PK: class Project < ActiveRecord::Base set_primary_key "sysid" end On 7/24/05, PaulCheeBinChin <PaulCheeBin.Chin-WVx2IYneKhdQ9++HdZ7WsQ@public.gmane.org> wrote:> > Hi, I just want to know if rails regard primary key (id) as integer, or can > I have primary key as varchar? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
can it be a varchar type? -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]On Behalf Of Aaron Rustad Sent: Monday, July 25, 2005 2:26 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] primary key By default, it looks for a id field of int, however, you can let ActiveRecord know which field you want as the PK: class Project < ActiveRecord::Base set_primary_key "sysid" end On 7/24/05, PaulCheeBinChin <PaulCheeBin.Chin-WVx2IYneKhdQ9++HdZ7WsQ@public.gmane.org> wrote:> > Hi, I just want to know if rails regard primary key (id) as integer, orcan> I have primary key as varchar? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi, can anyone enlighten me on this issue? I was not very keen on following rails way of having an id field with autoincrement. It seemly remove the readability of the id field, id = 1 , seemly means nothing as compare to id''Software''. But in the process of implementation, it seems not so easy to set_primary_key to something else, and have a key that can be edited. (I''m not sure if it is a limitation or I''m not doing it right) Should I forget about keeping the primary key to something that is more meaningful, and like just follow the rail''s way to have id key with 1,2,3,4 everywhere in the database? Anyone has experience on this?
to keep things simple (and rails working properly) I''d suggest keep the primary keys autoincrementing primary numbers, but you can ofcourse have a description column containing for example ''software'' to make it all easier or "meaningful" for yourself. Paul Chin wrote:>Hi, > >can anyone enlighten me on this issue? I was not very keen on following >rails way of having an id field with autoincrement. It seemly remove the >readability of the id field, id = 1 , seemly means nothing as compare to id>''Software''. But in the process of implementation, it seems not so easy to >set_primary_key to something else, and have a key that can be edited. (I''m >not sure if it is a limitation or I''m not doing it right) > >Should I forget about keeping the primary key to something that is more >meaningful, and like just follow the rail''s way to have id key with 1,2,3,4 >everywhere in the database? > >Anyone has experience on this? > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Follow the rails way! Besides how would you define meaningful entry on a table with few tens of thousand of elements? Paul Chin wrote:> Hi, > > can anyone enlighten me on this issue? I was not very keen on following > rails way of having an id field with autoincrement. It seemly remove the > readability of the id field, id = 1 , seemly means nothing as compare to id> ''Software''. But in the process of implementation, it seems not so easy to > set_primary_key to something else, and have a key that can be edited. (I''m > not sure if it is a limitation or I''m not doing it right) > > Should I forget about keeping the primary key to something that is more > meaningful, and like just follow the rail''s way to have id key with 1,2,3,4 > everywhere in the database? > > Anyone has experience on this? > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.com
Paul Chin wrote:> Hi,Hello.> can anyone enlighten me on this issue?FWIW, section 14.3, "Primary Keys and IDs" of the Rails book has an explanation that convinced my small brain of the benefits of this convention (pages 197-199). Regards, -- Bil Kleb http://fun3d.larc.nasa.gov