Hello, I have a (hopefully) quick question about working in Rails, and I was hoping somebody would be able to lend a hand. I''m trying to create an app and it has two models, let''s call them ''A'' and ''B''. The problem I''m having is that A includes a reference to B, and B includes a reference to A. As a result, if neither exist than both need to be created at the exact same time. However, when I call save() on an instance of A, Rails doesn''t seem to update that instance with it''s ID in the database, making it very hard to set B''s reference to A. Further, even if I had the ID, I have to do at least three DB transactions: Create A, Create B (with reference to A), Update A (with reference to B). So, my question is twofold: 1. Is there some way to find what ID an ActiveRecord object is given by the DB when I call save()? 2. Is there some way to do this more efficiently. Thanks. -- Trevor Johns --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello, I have a (hopefully) quick question about working in Rails, and I was hoping somebody would be able to lend a hand. I''m trying to create an app and it has two models, let''s call them ''A'' and ''B''. The problem I''m having is that A includes a reference to B, and B includes a reference to A. As a result, if neither exist than both need to be created at the exact same time. However, when I call save() on an instance of A, Rails doesn''t seem to update that instance with it''s ID in the database, making it very hard to set B''s reference to A. Further, even if I had the ID, I have to do at least three DB transactions: Create A, Create B (with reference to A), Update A (with reference to B). So, my question is twofold: 1. Is there some way to find what ID an ActiveRecord object is given by the DB when I call save()? 2. Is there some way to do this more efficiently. Thanks. -- Trevor Johns --~--~---------~--~----~------------~-------~--~----~ 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 Jan 7, 2007, at 8:33 PM, Trevor Johns wrote:> So, my question is twofold: > 1. Is there some way to find what ID an ActiveRecord object is > given by the DB when I call save()?Wrap the entire thing in a transaction.> 2. Is there some way to do this more efficiently.A.foos << B A.save -faisal --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---