Dear friends, I''m using rails 2.0.2. I have created a model sample and i have created columns using following codes <code> class CreateSamples < ActiveRecord::Migration def self.up create_table :samples, :id => false do |t| t.column :user_id, :integer, :limit => 10 t.column :name, :string, :limit => 20 t.column :age, :string, :limit => 3 t.timestamps end end def self.down drop_table :samples end end </code> The default primary key is id and it is auto incremented. I have set id => false and i don''t want to use it again. I need to set my user_id as primary key. Could any one suggest how to set the primary key other than id in rails 2.0.2 Thanks in advance Regards, Jose Martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in your user model write set_primary_key "user_id" On Jul 19, 9:22 am, dare ruby <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Dear friends, > > I''m using rails 2.0.2. I have created a model sample and i have created > columns using following codes > > <code> > class CreateSamples < ActiveRecord::Migration > def self.up > create_table :samples, :id => false do |t| > t.column :user_id, :integer, :limit => 10 > t.column :name, :string, :limit => 20 > t.column :age, :string, :limit => 3 > t.timestamps > end > end > > def self.down > drop_table :samples > end > end > </code> > > The default primary key is id and it is auto incremented. I have set id > => false and i don''t want to use it again. I need to set my user_id as > primary key. Could any one suggest how to set the primary key other than > id in rails 2.0.2 > > Thanks in advance > > Regards, > Jose Martin > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bala kishore Pulicherla wrote:> in your user model write > set_primary_key "user_id" > > On Jul 19, 9:22�am, dare ruby <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Dear bala, Thanks for your suggestion. its working fine now. Could you please provide details about auto incrementation for above mentioned primary key. Thanks in advance Regards, Jose Martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
u can put the id as itself as an auto increment and while ur creating the new user make the id to user_id and update. for ex. user = User.new(params[:user]) if user.save! user_id = user.id user.update_attribute(:user_id,"#{user.id}) respond_to |format| do ur - stuff end end mean while i'll find any :auto_increment option is there :( On Sat, Jul 19, 2008 at 2:11 PM, dare ruby <rails-mailing-list@andreas-s.net> wrote:> > Bala kishore Pulicherla wrote: > > in your user model write > > set_primary_key "user_id" > > > > On Jul 19, 9:22�am, dare ruby <rails-mailing-l...@andreas-s.net> > > Dear bala, > > Thanks for your suggestion. its working fine now. > > Could you please provide details about auto incrementation for above > mentioned primary key. > > Thanks in advance > > Regards, > Jose Martin > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
t.column :user_id, :primary_key, :null => false hope this will work for u :) On Sat, Jul 19, 2008 at 3:01 PM, bala kishore pulicherla < balumca21@gmail.com> wrote:> u can put the id as itself as an auto increment and while ur creating the > new user make the id to user_id and update. > > for ex. > user = User.new(params[:user]) > if user.save! > user_id = user.id > user.update_attribute(:user_id,"#{user.id}) > respond_to |format| do > ur - stuff > end > end > > mean while i'll find any :auto_increment option is there :( > > > On Sat, Jul 19, 2008 at 2:11 PM, dare ruby < > rails-mailing-list@andreas-s.net> wrote: > >> >> Bala kishore Pulicherla wrote: >> > in your user model write >> > set_primary_key "user_id" >> > >> > On Jul 19, 9:22�am, dare ruby <rails-mailing-l...@andreas-s.net> >> >> Dear bala, >> >> Thanks for your suggestion. its working fine now. >> >> Could you please provide details about auto incrementation for above >> mentioned primary key. >> >> Thanks in advance >> >> Regards, >> Jose Martin >> -- >> Posted via http://www.ruby-forum.com/. >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bala kishore Pulicherla wrote:> t.column :user_id, :primary_key, :null => false > > hope this will work for u :) > > On Sat, Jul 19, 2008 at 3:01 PM, bala kishore pulicherla <Dear Bala, Thanks for your very valuable information. I have used the above in my code and its working fine now Thanks regards, Jose Martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ur welcome. :) On Sat, Jul 19, 2008 at 4:17 PM, dare ruby <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Bala kishore Pulicherla wrote: > > t.column :user_id, :primary_key, :null => false > > > > hope this will work for u :) > > > > On Sat, Jul 19, 2008 at 3:01 PM, bala kishore pulicherla < > > Dear Bala, > > Thanks for your very valuable information. I have used the above in my > code and its working fine now > > Thanks > > regards, > Jose Martin > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---