<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -30,6 +30,8 @@ module DataMapper
       end
 
       class Proxy
+        instance_methods.each { |m| undef_method m unless %w[ __id__ __send__ class kind_of? should should_not ].include?(m) }
+
         def initialize() end
 
         def save</diff>
      <filename>lib/data_mapper/associations/many_to_many.rb</filename>
    </modified>
    <modified>
      <diff>@@ -26,11 +26,11 @@ module DataMapper
 
         class_eval &lt;&lt;-EOS, __FILE__, __LINE__
           def #{name}
-            #{name}_association.parent
+            #{name}_association
           end
 
           def #{name}=(parent_resource)
-            #{name}_association.parent = parent_resource
+            #{name}_association.replace(parent_resource)
           end
 
           private
@@ -49,11 +49,9 @@ module DataMapper
       end
 
       class Proxy
-        def parent
-          @parent_resource ||= @relationship.get_parent(@child_resource)
-        end
+        instance_methods.each { |m| undef_method m unless %w[ __id__ __send__ class kind_of? should should_not ].include?(m) }
 
-        def parent=(parent_resource)
+        def replace(parent_resource)
           @parent_resource = parent_resource
           @relationship.attach_parent(@child_resource, @parent_resource) if @parent_resource.nil? || !@parent_resource.new_record?
         end
@@ -76,6 +74,14 @@ module DataMapper
           @relationship   = relationship
           @child_resource = child_resource
         end
+
+        def parent
+          @parent_resource ||= @relationship.get_parent(@child_resource)
+        end
+
+        def method_missing(method, *args, &amp;block)
+          parent.__send__(method, *args, &amp;block)
+        end
       end # class Proxy
     end # module ManyToOne
   end # module Associations</diff>
      <filename>lib/data_mapper/associations/many_to_one.rb</filename>
    </modified>
    <modified>
      <diff>@@ -27,6 +27,16 @@ module DataMapper
 
         class_eval &lt;&lt;-EOS, __FILE__, __LINE__
           def #{name}
+            #{name}_association
+          end
+
+          def #{name}=(children)
+            #{name}_association.replace(children)
+          end
+
+          private
+
+          def #{name}_association
             @#{name}_association ||= begin
               relationship = self.class.relationships(repository.name)[:#{name}]
               association = Proxy.new(relationship, self)
@@ -40,13 +50,13 @@ module DataMapper
       end
 
       class Proxy
-        def children
-          @children ||= @relationship.get_children(@parent_resource)
-        end
+        instance_methods.each { |m| undef_method m unless %w[ __id__ __send__ class kind_of? should should_not ].include?(m) }
 
-        def children=(resources)
+        def replace(resources)
           each { |resource| remove_resource(resource) }
-          replace(resources)
+          append_resource(resources)
+          children.replace(resources)
+          self
         end
 
         def push(*resources)
@@ -92,6 +102,7 @@ module DataMapper
         def save
           save_resources(@dirty_children)
           @dirty_children = []
+          self
         end
 
         private
@@ -105,6 +116,10 @@ module DataMapper
           @dirty_children  = []
         end
 
+        def children
+          @children ||= @relationship.get_children(@parent_resource)
+        end
+
         def remove_resource(resource)
           begin
             repository(@relationship.repository_name) do
@@ -136,11 +151,7 @@ module DataMapper
         end
 
         def method_missing(method, *args, &amp;block)
-          if children.respond_to?(method)
-            children.__send__(method, *args, &amp;block)
-          else
-            super
-          end
+          children.__send__(method, *args, &amp;block)
         end
       end # class Proxy
     end # module OneToMany</diff>
      <filename>lib/data_mapper/associations/one_to_many.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,8 +30,7 @@ module DataMapper
           end
 
           def #{name}=(child_resource)
-            #{name}_association.clear
-            #{name}_association &lt;&lt; child_resource unless child_resource.nil?
+            #{name}_association.replace(child_resource.nil? ? [] : [ child_resource ])
           end
 
           private</diff>
      <filename>lib/data_mapper/associations/one_to_one.rb</filename>
    </modified>
    <modified>
      <diff>@@ -300,7 +300,7 @@ begin
       end
 
       it 'should save nil parents as NULL ids' do
-        p1,p2 = nil, nil
+        p1, p2 = nil, nil
 
         repository(:sqlite3) do
           p1 = Pie.new(:id =&gt; 20, :name =&gt; &quot;Pie20&quot;)
@@ -419,6 +419,20 @@ begin
         s.host.id.should == 10
       end
 
+      it 'should save the associated instances upon saving of parent when mass-assigned' do
+        repository(:sqlite3) do
+          h = Host.create(:id =&gt; 10, :name =&gt; 'host10', :slices =&gt; [ Slice.new(:id =&gt; 10, :name =&gt; 'slice10') ])
+        end
+
+        s = repository(:sqlite3) do
+          Slice.first(:id =&gt; 10)
+        end
+
+        s.should_not be_nil
+        s.host.should_not be_nil
+        s.host.id.should == 10
+      end
+
       describe &quot;many-to-one and one-to-many associations combined&quot; do
         before do
           @adapter = repository(:sqlite3).adapter</diff>
      <filename>spec/integration/association_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,7 +23,7 @@ describe &quot;DataMapper::Associations::ManyToOne&quot; do
         @parent.should_receive(:new_record?).and_return(false)
         @relationship.should_receive(:attach_parent).with(@child, @parent)
 
-        @association.parent = @parent
+        @association.replace(@parent)
       end
     end
   end</diff>
      <filename>spec/unit/associations/many_to_one_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -110,7 +110,7 @@ end
 
 describe DataMapper::Associations::OneToMany::Proxy do
   before do
-    @parent = mock(&quot;parent&quot;)
+    @parent = mock(&quot;parent&quot;, :new_record? =&gt; true)
     @resource = mock(&quot;resource&quot;, :null_object =&gt; true)
     @collection = []
     @repository = mock(&quot;repository&quot;, :save =&gt; nil)
@@ -126,8 +126,6 @@ describe DataMapper::Associations::OneToMany::Proxy do
         @collection.should_receive(:&lt;&lt;).with(@resource).once.and_return(@collection)
 
         @association &lt;&lt; @resource
-
-        @association.instance_variable_get(&quot;@dirty_children&quot;).should be_empty
       end
     end
 
@@ -138,13 +136,9 @@ describe DataMapper::Associations::OneToMany::Proxy do
         @collection.should_receive(:&lt;&lt;).with(@resource).once.and_return(@collection)
 
         @association &lt;&lt; @resource
-
-        @association.instance_variable_get(&quot;@dirty_children&quot;).should_not be_empty
       end
 
-      it &quot;should save the resource after the parent is saved&quot; do
-
-      end
+      it &quot;should save the resource after the parent is saved&quot;
 
       it &quot;should add the parent's keys to the resource after the parent is saved&quot;
     end
@@ -201,17 +195,17 @@ describe DataMapper::Associations::OneToMany::Proxy do
       @relationship.should_receive(:attach_parent).with(@resource, nil).once
       @resource.should_receive(:save).with(no_args).once
 
-      @association.children = @children
+      @association.replace(@children)
     end
 
     it &quot;should replace the children in the collection&quot; do
       @children.should_not == @collection
-      @association.children.should == @collection
+      @association.entries.should == @collection
 
-      @association.children = @children
+      @association.replace(@children)
 
-      @collection.should == @children
-      @association.children.object_id.should == @collection.object_id
+      @children.should == @collection  # collection was modified
+      @association.entries.should == @collection
     end
   end
 </diff>
      <filename>spec/unit/associations/one_to_many_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5b3c7c27c694b586d0ec2f807ae9811407223c84</id>
    </parent>
  </parents>
  <author>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </author>
  <url>http://github.com/sam/dm-core/commit/af80e61f2207c9de75d3d1ca84168df3cbadd340</url>
  <id>af80e61f2207c9de75d3d1ca84168df3cbadd340</id>
  <committed-date>2008-05-09T02:03:58-07:00</committed-date>
  <authored-date>2008-05-09T02:03:58-07:00</authored-date>
  <message>Updated Association Proxy classes to encapsulate their state better

* The ManyToOne::Proxy class would return the parent resource directly,
  when instead it should return a copy of itself, and route all method
  calls through its instance (like save), handing off anything unknown
  to the parent.
* Updated the Proxy classes to use a &quot;blank slate&quot;, and have all of their
  instance methods removed.  This would allow them to proxy most method
  calls to the underlying objects like a good proxy object should.
* Allow mass-assign to OneToMany associations</message>
  <tree>f2a8e0e698baaa335305583c80850f315e9d4578</tree>
  <committer>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </committer>
</commit>
