Skip to content

Instantly share code, notes, and snippets.

@keichan34
Created September 5, 2013 11:33
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save keichan34/6448987 to your computer and use it in GitHub Desktop.
Save keichan34/6448987 to your computer and use it in GitHub Desktop.
Get Marshal.dump and Marshal.load to load cached association objects ( Whatever.includes(:example_models) ), as well.
module ActiveRecordMarshalable
def marshal_dump
[attributes, self.association_cache, instance_variable_get(:@new_record)]
end
def marshal_load data
send :initialize, data[0]
instance_variable_set :@association_cache, data[1]
instance_variable_set :@new_record, data[2]
end
end
class ExampleModel < ActiveRecord::Base
include ActiveRecordMarshalable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment