Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @keichan34 keichan34 created this gist Sep 5, 2013.
    11 changes: 11 additions & 0 deletions active_record_marshalable.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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
    3 changes: 3 additions & 0 deletions example_model.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    class ExampleModel < ActiveRecord::Base
    include ActiveRecordMarshalable
    end