Paul Dowman
2008-Feb-22 22:51 UTC
marshaling ActiveRecord objects: how to unload associations?
I''m marshaling ActiveRecord objects, and I want them to be as small as possible. How can I unload everything that can be reloaded from the database? If they''re marshaled before any of the associations are referenced then the referenced objects aren''t dumped. But if the association has been loaded, how can I unload it? AssociationProxy.reset doesn''t seem to do it. It seems that after the AssociationProxy has been touched at all then dumping the object causes the AssociationProxy to load everything. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alex Le
2008-Mar-04 19:49 UTC
Re: marshaling ActiveRecord objects: how to unload associati
Paul Dowman wrote:> I''m marshaling ActiveRecord objects, and I want them to be as small as > possible. How can I unload everything that can be reloaded from the > database? > > If they''re marshaled before any of the associations are referenced > then the referenced objects aren''t dumped. But if the association has > been loaded, how can I unload it? AssociationProxy.reset doesn''t seem > to do it. It seems that after the AssociationProxy has been touched at > all then dumping the object causes the AssociationProxy to load > everything. > > Thanks!Try calling these methods on your activerecord: clear_aggregation_cache clear_association_cache They are not private/protected so you can call them from outside an object as well. -- 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 -~----------~----~----~----~------~----~------~--~---
alexmle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Mar-04 19:50 UTC
Re: marshaling ActiveRecord objects: how to unload associations?
Try calling these methods on your activerecord: clear_aggregation_cache clear_association_cache They are not private/protected so you can call them from outside an object as well. On Feb 22, 2:51 pm, Paul Dowman <li...-pLmsWd37BPCQWHG76I6BsA@public.gmane.org> wrote:> I''m marshaling ActiveRecord objects, and I want them to be as small as > possible. How can I unload everything that can be reloaded from the > database? > > If they''re marshaled before any of the associations are referenced > then the referenced objects aren''t dumped. But if the association has > been loaded, how can I unload it? AssociationProxy.reset doesn''t seem > to do it. It seems that after the AssociationProxy has been touched at > all then dumping the object causes the AssociationProxy to load > everything. > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---