how can we unset an Active Record relationship of an instance on the fly? i have this: class User < AR has_one :profile end @user is the instance of User, and it has relationship to profile (@user.profile). the profile contain a large data, and it has been loaded into @user. the problem is, i need to save the @user into session without saving the profile (to avoid repetitive SQL lookup to user information, and to increase performance) but the current situation is, the profile is also saved into the session. my session is stored in the database, so by also saving this profile object, it will eat my database space. can it be done? 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 -~----------~----~----~----~------~----~------~--~---
Running object.clear_association_cache before storing it in the session should do the trick. -Jonathan. On 10/12/06, Adrian Liem <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > how can we unset an Active Record relationship of an instance on the > fly? i have this: > > class User < AR > has_one :profile > end > > @user is the instance of User, and it has relationship to profile > (@user.profile). the profile contain a large data, and it has been > loaded into @user. the problem is, i need to save the @user into session > without saving the profile (to avoid repetitive SQL lookup to user > information, and to increase performance) > > but the current situation is, the profile is also saved into the > session. my session is stored in the database, so by also saving this > profile object, it will eat my database space. > > can it be done? > 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 -~----------~----~----~----~------~----~------~--~---
Jonathan Viney wrote:> Running object.clear_association_cache before storing it in the session > should do the trick. > > -Jonathan.thanks but it''s not working here''s the code where i put my clear_association_cache: @session[:user] ||= {} user ||= @session[:user][subdomain] || User.find_by_login(subdomain) user.clear_association_cache @session[:user][subdomain] = user and my dump result: adrianliem: !ruby/object:User ad: attributes: salt: fcb964..... updated_at: 2006-10-12 14:12:47 crypted_password: 7ca5..... id: "2" remember_token: login: adrianliem created_at: 2006-10-08 15:43:34 email: adrianliem@localhost document: profile: !ruby/object:Profile attributes: certified: city: tokyo dob: "1980-10-09" location: message: i''ve googled about the clear_association_cache, and it seems to be work for others, but somehow it does not work in mine. any further suggestion please? 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 -~----------~----~----~----~------~----~------~--~---