I used a PHP function mysql_insert_id to get the ID generated from the previous INSERT operation. I wonder if there is something similar that I can use in Ruby/Rails? Thanks in advance! -- 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 -~----------~----~----~----~------~----~------~--~---
Once you save @object, just use @object.id. -- Building an e-commerce site with Rails? http://agilewebdevelopment.com/rails-ecommerce Meet up at RailsConf: http://railsconf2007.conferencemeetup.com/ On Apr 13, 2007, at 3:56 PM, Gordon Lo wrote:> > I used a PHP function mysql_insert_id to get the ID generated from the > previous INSERT operation. I wonder if there is something similar > that I > can use in Ruby/Rails? > > Thanks in advance!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Benjamin Curtis wrote:> Once you save @object, just use @object.id. >Thanks Benjamin. So you mean @object.id will be the auto-increment id created in MySql? All I want to do is that - in one single page, allow people to sign up for a company and register for many users (in the same company). Once user clicks submit, it will first create the company (i.e. insert into company table and return id) and then add each user to users table (using the same company_id) -- 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 -~----------~----~----~----~------~----~------~--~---
On Apr 13, 2007, at 5:43 PM, Gordon Lo wrote:> > Benjamin Curtis wrote: >> Once you save @object, just use @object.id. >> > > Thanks Benjamin. So you mean @object.id will be the auto-increment id > created in MySql? > > All I want to do is that - in one single page, allow people to sign up > for a company and register for many users (in the same company). Once > user clicks submit, it will first create the company (i.e. insert into > company table and return id) and then add each user to users table > (using the same company_id) >Yes, it is the id provided by MySQL. Assuming you have the relationship between company and users in your models, you can also do something like this: @company = Company.create(params[:company]) params[:users].each do |user| @company.users.create(user) end -- Building an e-commerce site with Rails? http://agilewebdevelopment.com/rails-ecommerce Meet up at RailsConf: http://railsconf2007.conferencemeetup.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 -~----------~----~----~----~------~----~------~--~---