<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -494,6 +494,32 @@ module DataMapper
       super || model.public_methods(false).include?(method.to_s) || relationships.has_key?(method)
     end
 
+    # TODO: add docs
+    # @api private
+    def _dump(*)
+      Marshal.dump([ query, to_a ])
+    end
+
+    # TODO: add docs
+    # @api private
+    def self._load(marshalled)
+      query, array = Marshal.load(marshalled)
+
+      # XXX: IMHO it is a code smell to be forced to use allocate
+      # and instance_variable_set to load an object.  You should
+      # be able to use a constructor to provide all the info needed
+      # to initialize an object.  This should be fixed in the edge
+      # branch dkubb/dm-core
+
+      collection = allocate
+      collection.instance_variable_set(:@query,          query)
+      collection.instance_variable_set(:@array,          array)
+      collection.instance_variable_set(:@loaded,         true)
+      collection.instance_variable_set(:@key_properties, collection.send(:model).key(collection.repository.name))
+      collection.instance_variable_set(:@cache,          {})
+      collection
+    end
+
     protected
 
     ##</diff>
      <filename>lib/dm-core/collection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -385,6 +385,13 @@ module DataMapper
       Query.new(repository, self, query.merge(conditions))
     end
 
+    # TODO: add docs
+    # @api private
+    def _load(marshalled)
+      repository_name, attributes = Marshal.load(marshalled)
+      repository(repository_name) { new(attributes) }
+    end
+
     def typecast_key(key)
       self.key(repository_name).zip(key).map { |k, v| k.typecast(v) }
     end</diff>
      <filename>lib/dm-core/model.rb</filename>
    </modified>
    <modified>
      <diff>@@ -512,6 +512,19 @@ module DataMapper
       &quot;#&lt;Property:#{@model}:#{@name}&gt;&quot;
     end
 
+    # TODO: add docs
+    # @api private
+    def _dump(*)
+      Marshal.dump([ repository, model, name ])
+    end
+
+    # TODO: add docs
+    # @api private
+    def self._load(marshalled)
+      repository, model, name = Marshal.load(marshalled)
+      model.properties(repository.name)[name]
+    end
+
     private
 
     def initialize(model, name, type, options = {})</diff>
      <filename>lib/dm-core/property.rb</filename>
    </modified>
    <modified>
      <diff>@@ -151,6 +151,55 @@ module DataMapper
       &quot;#&lt;#{self.class.name} #{attrs.map { |(k,v)| &quot;@#{k}=#{v.inspect}&quot; } * ' '}&gt;&quot;
     end
 
+    # TODO: add docs
+    # @api public
+    def to_hash
+      hash = {
+        :reload       =&gt; reload?,
+        :unique       =&gt; unique?,
+        :offset       =&gt; offset,
+        :order        =&gt; order,
+        :add_reversed =&gt; add_reversed?,
+        :fields       =&gt; fields,
+      }
+
+      hash[:limit]    = limit    unless limit    == nil
+      hash[:links]    = links    unless links    == []
+      hash[:includes] = includes unless includes == []
+
+      conditions  = {}
+      raw_queries = []
+      bind_values = []
+
+      conditions.each do |condition|
+        if condition[0] == :raw
+          raw_queries &lt;&lt; condition[1]
+          bind_values &lt;&lt; condition[2]
+        else
+          operator, property, bind_value = condition
+          conditions[ Query::Operator.new(property, operator) ] = bind_value
+        end
+      end
+
+      if raw_queries.any?
+        hash[:conditions] = [ raw_queries.join(' ') ].concat(bind_values)
+      end
+
+      hash.update(conditions)
+    end
+
+    # TODO: add docs
+    # @api private
+    def _dump(*)
+      Marshal.dump([ repository, model, to_hash ])
+    end
+
+    # TODO: add docs
+    # @api private
+    def self._load(marshalled)
+      new(*Marshal.load(marshalled))
+    end
+
     private
 
     def initialize(repository, model, options = {})</diff>
      <filename>lib/dm-core/query.rb</filename>
    </modified>
    <modified>
      <diff>@@ -91,6 +91,14 @@ module DataMapper
       &quot;#&lt;DataMapper::Repository:#{@name}&gt;&quot;
     end
 
+    def _dump(*)
+      name.to_s
+    end
+
+    def self._load(marshalled)
+      new(marshalled.to_sym)
+    end
+
     private
 
     def initialize(name)</diff>
      <filename>lib/dm-core/repository.rb</filename>
    </modified>
    <modified>
      <diff>@@ -528,6 +528,19 @@ module DataMapper
       model.to_query(repository, key, query) unless new_record?
     end
 
+    # TODO: add docs
+    # @api private
+    def _dump(*)
+      repository_name = repository.name
+      attributes      = {}
+
+      model.properties(repository_name).slice(*loaded_attributes).compact.each do |property|
+        attributes[property.name] = property.get(self) if property.writer_visibility == :public
+      end
+
+      Marshal.dump([ repository_name, attributes ])
+    end
+
     protected
 
     def properties</diff>
      <filename>lib/dm-core/resource.rb</filename>
    </modified>
    <modified>
      <diff>@@ -127,6 +127,10 @@ if ADAPTER
       results.first.should == bob
     end
 
+    it 'should be serializable with Marshal' do
+      Marshal.load(Marshal.dump(Zebra.all)).should == Zebra.all
+    end
+
     describe 'model proxying' do
       it 'should delegate to a model method' do
         stripes = @model.first.stripes</diff>
      <filename>spec/integration/collection_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,22 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
 gem 'fastercsv', '~&gt;1.4.0'
 require 'fastercsv'
 
+describe DataMapper::Property do
+  before do
+    module PropertySpec
+      class Resource
+        include DataMapper::Resource
+      end
+    end
+
+    @property = PropertySpec::Resource.property :id, DM::Serial
+  end
+
+  it 'should be serializable with Marshal' do
+    Marshal.load(Marshal.dump(@property)).should == @property
+  end
+end
+
 if ADAPTER
   describe DataMapper::Property, &quot;with #{ADAPTER}&quot; do
     describe &quot; tracking strategies&quot; do</diff>
      <filename>spec/integration/property_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -125,6 +125,14 @@ if ADAPTER
   end
 
   describe DataMapper::Query, &quot;with #{ADAPTER}&quot; do
+    before do
+      @query = DataMapper::Query.new(repository(ADAPTER), QuerySpec::SailBoat)
+    end
+
+    it 'should be serializable with Marshal' do
+      Marshal.load(Marshal.dump(@query)).should == @query
+    end
+
     describe '#unique' do
       include LoggingHelper
 </diff>
      <filename>spec/integration/query_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -21,6 +21,10 @@ if ADAPTER
       @query      = DataMapper::Query.new(@repository, @model)
     end
 
+    it 'should be serializable with Marshal' do
+      Marshal.load(Marshal.dump(@repository)).should == @repository
+    end
+
     it &quot;should throw an exception if the named repository is unknown&quot; do
       r = DataMapper::Repository.new(:completely_bogus)
       lambda { r.adapter }.should raise_error(ArgumentError)</diff>
      <filename>spec/integration/repository_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -16,7 +16,11 @@ if ADAPTER
       repository(ADAPTER) { @zoo.save }
     end
 
-  # --- Move somewhere ----
+    it 'should be serializable with Marshal' do
+      Marshal.load(Marshal.dump(@zoo)).should == @zoo
+    end
+
+    # --- Move somewhere ----
     it &quot;should be able to destroy objects&quot; do
       lambda { @zoo.destroy.should be_true }.should_not raise_error
     end</diff>
      <filename>spec/integration/resource_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7ec0cc5ecda95f8bff827cce81a54dda803213f8</id>
    </parent>
  </parents>
  <author>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </author>
  <url>http://github.com/sam/dm-core/commit/83ea752d5604726b00ff11c55c0fbd2c39607c16</url>
  <id>83ea752d5604726b00ff11c55c0fbd2c39607c16</id>
  <committed-date>2009-01-04T00:48:56-08:00</committed-date>
  <authored-date>2009-01-04T00:48:56-08:00</authored-date>
  <message>Updated Resource and Collection to be Marshalable</message>
  <tree>c41a45d0c15d328e0715f33750875b0a72670777</tree>
  <committer>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </committer>
</commit>
