I have a hash with ActiveRecord objects in them that I am marshaling and storing as a constant in my migration files--so I can store additional information needed while I do migrations. I am able to do migrations just fine, which tells me that adding the constant (which is equal to them marshaled hash) to the migrate class doesn''t cause any problems. However, when I try to do a Marshal.load(MigrateClass::HASH_OBJ) I get the following error: undefined class/module MyActiveRecordClassName ...where MyActiveRecordClassName is the first ActiveRecord reference made in the marshaled hash. I know that objects that "include bindings, procedure or method objects, instances of class IO, or singleton objects" (see ruby docs) cannot be marshaled. Do ActiveRecord objects include any of these? Can ActiveRecord objects be marshaled? -- 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 -~----------~----~----~----~------~----~------~--~---
Vishnu Gopal
2006-Sep-26 18:52 UTC
Re: Marshaling Objects with ActiveRecord Objects in them
They can be, try adding model :MyActiveRecordClassName to the ApplicationController Vish On 9/27/06, Caleb <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I have a hash with ActiveRecord objects in them that I am marshaling and > storing as a constant in my migration files--so I can store additional > information needed while I do migrations. I am able to do migrations > just fine, which tells me that adding the constant (which is equal to > them marshaled hash) to the migrate class doesn''t cause any problems. > > However, when I try to do a Marshal.load(MigrateClass::HASH_OBJ) I get > the following error: > undefined class/module MyActiveRecordClassName > > ...where MyActiveRecordClassName is the first ActiveRecord reference > made in the marshaled hash. I know that objects that "include bindings, > procedure or method objects, instances of class IO, or singleton > objects" (see ruby docs) cannot be marshaled. Do ActiveRecord objects > include any of these? Can ActiveRecord objects be marshaled? > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Caleb wrote:> I know that objects that "include bindings, > procedure or method objects, instances of class IO, or singleton > objects" (see ruby docs) cannot be marshaled. Do ActiveRecord objects > include any of these? Can ActiveRecord objects be marshaled?I''m pretty sure that ActiveRecord objects CAN be marshaled. I am able to do the following running ''./script/console'' w/o any errors:>> obj1 = MyActiveRecordClass.find_by_id(1) >> obj2 = Marshal.load(Marshal.dump(obj1)) >> obj1 == obj2=> true I get the above "undefined class/module MyActiveRecordClassName" error even though my $: path variable contains a reference to my ''models'' directory where all of my active record classes are defined. Any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
Vishnu Gopal wrote:> They can be, try adding > model :MyActiveRecordClassName > to the ApplicationControllerThanks Vish! That did the trick! Note that I had to use the unserscore-lowercase version of the class names for the model symbols. Example: model :my_active_record_class_name -- 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 -~----------~----~----~----~------~----~------~--~---