Hi, How do I save an object with its children into the session? By default AR cleans the children when I put the object there. And if someone knows any docs about that please show the link. Thks, Bruno Reis --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Oct-11 18:11 UTC
Re: How to save an object with its associations into session
What do you mean it cleans by default ? Start session[:user] = User.find(1) then you can do this session[:user].id or that? session[:user].contacts.length -- 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 -~----------~----~----~----~------~----~------~--~---
Bruno Reis
2007-Oct-11 22:53 UTC
Re: How to save an object with its associations into session
that is what I can''t do: session[:user].contacts.length On Oct 11, 11:11 am, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> What do you mean it cleans by default ? > > Start > session[:user] = User.find(1) > > then you can do this > session[:user].id > > or that? > session[:user].contacts.length > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Josh Susser
2007-Oct-12 00:42 UTC
Re: How to save an object with its associations into session
Bruno Reis wrote:> How do I save an object with its children into the session? By default > AR cleans the children when I put the object there. > > And if someone knows any docs about that please show the link.In general, it''s a *bad* idea to put a full AR object in the session. It mostly works, but it can get you in trouble. The accepted best practice is to store the id in the session, then fetch the record from the database when you need it. That way you avoid the nasty synchronization issues etc. session[:user_id] = user.id then later... user = User.find(session[:user.id]) -- Josh Susser http://blog.hasmanythrough.com -- 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 -~----------~----~----~----~------~----~------~--~---