in my code i''m calling save on an object. The id gets created as the object is persisted. How can i retrieve that newly created id? I guess I could query the table again using the other attributes of the object but is there another way? thanks in advance. larry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060311/6d88fbca/attachment.html
If I am understanding you correctly you have: myObj = Object.new() .... myObj.save You can now just use: myObj.id now that it has been saved. ~ Ben On 3/11/06, Larry White <ljw1001@gmail.com> wrote:> in my code i''m calling save on an object. The id gets created as the object > is persisted. How can i retrieve that newly created id? I guess I could > query the table again using the other attributes of the object but is there > another way? > > thanks in advance. > > larry > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Ben Reubenstein http://www.benr75.com
Hi Ben Suppose you have an object (@myObj) and another object wich is a subclass of the first one (using has_one and belongs_to looks like @myObj.subObj) If I want to save them to their (different) databases: Do I have to save first the @subObj and then the @myObj or is there an easier way to save objects into their specific database? I mean, if I have @myObj = Object.new() @subObj = SubObject.new(...) Can I do something like this? @myObj.subObj = @subObj @myObj.save Or do I have to do something like this? @subObj.save @myObj.subObj = @subObj @myObj.save Thanks, Rafa Ben Reubenstein wrote:> If I am understanding you correctly you have: > > myObj = Object.new() > .... > myObj.save > > You can now just use: > > myObj.id now that it has been saved. > > ~ Ben > > On 3/11/06, Larry White <ljw1001@gmail.com> wrote: >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > -- > Ben Reubenstein > http://www.benr75.com-- Posted via http://www.ruby-forum.com/.