I currently have an activerecord object that I make available to all my controllers through a variable called @menu that I set in application.rb. @menu has a one to many association with it''s children (MenuItems). @menu has a virtual attribute that I set to let it know which menu_item is currently selected. I made it virtual just because I don''t want the selection to be saved to the database. The problem I''m having is that in some parts of my application I have a reference to one of the child objects which use to get a reference to the parent object (@menu) which, it appears, re-queries the database giving me a reference to the saved @menu rather than the one that has the virtual attribute set on it. How can I get around this? Thanks in advance for any advice you can offer me. -Mike --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
mike wrote:> The problem > I''m having is that in some parts of my application I have a reference > to one of the child objects which use to get a reference to the parent > object (@menu) which, it appears, re-queries the databasehi there, what you want is for model.child.parent to return model however, this isn''t what ActiveRecord gives you at the moment. there''s a ticket to work around this. http://dev.rubyonrails.org/ticket/8130 but I don''t think it''s going to get added to trunk. My suggestion is keep display data in the display. Chuck it into the session session[:menu_selection][@menu.id] = @child.id or something. -- 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 -~----------~----~----~----~------~----~------~--~---
ok cool. i think this is over my head for now. thanks for your help. i ended up doing something like what you suggested. On 10/4/07, Matthew Rudy <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > mike wrote: > > The problem > > I''m having is that in some parts of my application I have a reference > > to one of the child objects which use to get a reference to the parent > > object (@menu) which, it appears, re-queries the database > > hi there, > > what you want is for > > model.child.parent to return model > however, this isn''t what ActiveRecord gives you at the moment. > > there''s a ticket to work around this. > http://dev.rubyonrails.org/ticket/8130 > > but I don''t think it''s going to get added to trunk. > > My suggestion is keep display data in the display. > Chuck it into the session > session[:menu_selection][@menu.id] = @child.id > > or something. > > -- > 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 -~----------~----~----~----~------~----~------~--~---