<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -38,13 +38,8 @@ module DataMapper
           def #{name}_association
             @#{name}_association ||= begin
               relationship = self.class.relationships(repository.name)[:#{name}]
-
-              association = Proxy.new(relationship, self) do
-                relationship.get_parent(self)
-              end
-
+              association = Proxy.new(relationship, self)
               child_associations &lt;&lt; association
-
               association
             end
           end
@@ -55,7 +50,7 @@ module DataMapper
 
       class Proxy
         def parent
-          @parent_resource ||= @parent_loader.call
+          @parent_resource ||= @relationship.get_parent(@child_resource)
         end
 
         def parent=(parent_resource)
@@ -74,13 +69,12 @@ module DataMapper
 
         private
 
-        def initialize(relationship, child_resource, &amp;parent_loader)
+        def initialize(relationship, child_resource)
 #          raise ArgumentError, &quot;+relationship+ should be a DataMapper::Association::Relationship, but was #{relationship.class}&quot;, caller unless Relationship === relationship
 #          raise ArgumentError, &quot;+child_resource+ should be a DataMapper::Resource, but was #{child_resource.class}&quot;, caller              unless Resource     === child_resource
 
           @relationship   = relationship
           @child_resource = child_resource
-          @parent_loader  = parent_loader
         end
       end # class Proxy
     end # module ManyToOne</diff>
      <filename>lib/data_mapper/associations/many_to_one.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,7 +29,7 @@ module DataMapper
           def #{name}
             @#{name}_association ||= begin
               relationship = self.class.relationships(repository.name)[:#{name}]
-              association = Proxy.new(relationship, self, relationship.get_children(self))
+              association = Proxy.new(relationship, self)
               parent_associations &lt;&lt; association
               association
             end
@@ -40,43 +40,52 @@ module DataMapper
       end
 
       class Proxy
+        def children
+          @children ||= @relationship.get_children(@parent_resource)
+        end
+
+        def children=(resources)
+          each { |resource| remove_resource(resource) }
+          replace(resources)
+        end
+
         def push(*resources)
           append_resource(resources)
-          @children.push(*resources)
+          children.push(*resources)
           self
         end
 
         def unshift(*resources)
           append_resource(resources)
-          @children.unshift(*resources)
+          children.unshift(*resources)
           self
         end
 
         def &lt;&lt;(resource)
           append_resource([ resource ])
-          @children &lt;&lt; resource
+          children &lt;&lt; resource
           self
         end
 
         def pop
-          remove_resource(@children.pop)
+          remove_resource(children.pop)
         end
 
         def shift
-          remove_resource(@children.shift)
+          remove_resource(children.shift)
         end
 
         def delete(resource, &amp;block)
-          remove_resource(@children.delete(resource, &amp;block))
+          remove_resource(children.delete(resource, &amp;block))
         end
 
         def delete_at(index)
-          remove_resource(@children.delete_at(index))
+          remove_resource(children.delete_at(index))
         end
 
         def clear
           each { |resource| remove_resource(resource) }
-          @children.clear
+          children.clear
           self
         end
 
@@ -87,14 +96,12 @@ module DataMapper
 
         private
 
-        def initialize(relationship, parent_resource, collection)
+        def initialize(relationship, parent_resource)
 #          raise ArgumentError, &quot;+relationship+ should be a DataMapper::Association::Relationship, but was #{relationship.class}&quot;, caller unless Relationship === relationship
 #          raise ArgumentError, &quot;+parent_resource+ should be a DataMapper::Resource, but was #{parent_resource.class}&quot;, caller            unless Resource     === parent_resource
-#          raise ArgumentError, &quot;+collection+ should be a DataMapper::Collection, but was #{collection.class}&quot;, caller                    unless Collection   === parent_resource
 
           @relationship    = relationship
           @parent_resource = parent_resource
-          @children        = collection
           @dirty_children  = []
         end
 
@@ -105,7 +112,7 @@ module DataMapper
               resource.save
             end
           rescue
-            @children &lt;&lt; resource
+            children &lt;&lt; resource
             raise
           end
           resource
@@ -129,8 +136,8 @@ module DataMapper
         end
 
         def method_missing(method, *args, &amp;block)
-          if @children.respond_to?(method)
-            @children.__send__(method, *args, &amp;block)
+          if children.respond_to?(method)
+            children.__send__(method, *args, &amp;block)
           else
             super
           end</diff>
      <filename>lib/data_mapper/associations/one_to_many.rb</filename>
    </modified>
    <modified>
      <diff>@@ -39,7 +39,7 @@ module DataMapper
           def #{name}_association
             @#{name}_association ||= begin
               relationship = self.class.relationships(repository.name)[:#{name}]
-              association = Associations::OneToMany::Proxy.new(relationship, self, relationship.get_children(self))
+              association = Associations::OneToMany::Proxy.new(relationship, self)
               parent_associations &lt;&lt; association
               association
             end</diff>
      <filename>lib/data_mapper/associations/one_to_one.rb</filename>
    </modified>
    <modified>
      <diff>@@ -109,21 +109,20 @@ describe DataMapper::Associations::OneToMany do
 end
 
 describe DataMapper::Associations::OneToMany::Proxy do
-  describe &quot;when adding a resource&quot; do
-    before do
-      @parent = mock(&quot;parent&quot;)
-      @resource = mock(&quot;resource&quot;, :null_object =&gt; true)
-      @collection = mock(&quot;collection&quot;)
-      @repository = mock(&quot;repository&quot;, :save =&gt; nil)
-      @relationship = mock(&quot;relationship&quot;)
-      @association = DataMapper::Associations::OneToMany::Proxy.new(@relationship, @parent, @collection)
-    end
+  before do
+    @parent = mock(&quot;parent&quot;)
+    @resource = mock(&quot;resource&quot;, :null_object =&gt; true)
+    @collection = []
+    @repository = mock(&quot;repository&quot;, :save =&gt; nil)
+    @relationship = mock(&quot;relationship&quot;, :get_children =&gt; @collection, :repository_name =&gt; :a_symbol)
+    @association = DataMapper::Associations::OneToMany::Proxy.new(@relationship, @parent)
+  end
 
+  describe &quot;when adding a resource&quot; do
     describe &quot;with a persisted parent&quot; do
       it &quot;should save the resource&quot; do
         @parent.should_receive(:new_record?).with(no_args).once.and_return(false)
-        @relationship.should_receive(:attach_parent).with(@resource, @parent)
-        @relationship.should_receive(:repository_name).with(no_args).once.and_return(:a_symbol)
+        @relationship.should_receive(:attach_parent).with(@resource, @parent).once
         @collection.should_receive(:&lt;&lt;).with(@resource).once.and_return(@collection)
 
         @association &lt;&lt; @resource
@@ -152,26 +151,73 @@ describe DataMapper::Associations::OneToMany::Proxy do
   end
 
   describe &quot;when deleting a resource&quot; do
-    it &quot;should delete the resource from the database&quot;
+    before do
+      @collection.stub!(:delete).and_return(@resource)
+      @relationship.stub!(:attach_parent).once
+    end
 
-    it &quot;should delete the resource from the association&quot;
+    it &quot;should delete the resource from the database&quot; do
+      @resource.should_receive(:save).with(no_args).once
 
-    it &quot;should erase the ex-parent's keys from the resource&quot;
+      @association.delete(@resource)
+    end
+
+    it &quot;should delete the resource from the association&quot; do
+      @collection.should_receive(:delete).with(@resource).once.and_return(@resource)
+
+      @association.delete(@resource)
+    end
+
+    it &quot;should erase the ex-parent's keys from the resource&quot; do
+      @relationship.should_receive(:attach_parent).with(@resource, nil).once
+
+      @association.delete(@resource)
+    end
   end
 
   describe &quot;when deleting the parent&quot; do
+    it &quot;should delete all the children without calling destroy if relationship :dependent is :delete_all&quot;
+
+    it &quot;should destroy all the children if relationship :dependent is :destroy&quot;
+
+    it &quot;should set the children's parent key to nil if relationship :dependent is :nullify&quot;
 
+    it &quot;should restrict the parent from being deleted if a child remains if relationship :dependent is restrict&quot;
+
+    it &quot;should be restrict by default if relationship :dependent is not specified&quot;
   end
 
-  describe &quot;with an unsaved parent&quot; do
-    describe &quot;when deleting a resource from an unsaved parent&quot; do
-      it &quot;should remove the resource from the association&quot; do
+  describe &quot;when replacing the children&quot; do
+    before do
+      @children = [
+        mock(&quot;child 1&quot;),
+        mock(&quot;child 2&quot;),
+      ]
+      @collection &lt;&lt; @resource
+      @relationship.stub!(:attach_parent)
+    end
 
-      end
+    it &quot;should remove each resource&quot; do
+      @relationship.should_receive(:attach_parent).with(@resource, nil).once
+      @resource.should_receive(:save).with(no_args).once
+
+      @association.children = @children
     end
-  end
-end
 
-describe &quot;when changing a resource's parent&quot; do
+    it &quot;should replace the children in the collection&quot; do
+      @children.should_not == @collection
+      @association.children.should == @collection
 
+      @association.children = @children
+
+      @collection.should == @children
+      @association.children.object_id.should == @collection.object_id
+    end
+  end
+
+  describe &quot;with an unsaved parent&quot; do
+    describe &quot;when deleting a resource from an unsaved parent&quot; do
+      it &quot;should remove the resource from the association&quot;
+    end
+  end
 end</diff>
      <filename>spec/unit/associations/one_to_many_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>73f5841d62c9212e49e064b10db9d37b277eacae</id>
    </parent>
  </parents>
  <author>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </author>
  <url>http://github.com/sam/dm-core/commit/5b3c7c27c694b586d0ec2f807ae9811407223c84</url>
  <id>5b3c7c27c694b586d0ec2f807ae9811407223c84</id>
  <committed-date>2008-05-09T00:53:51-07:00</committed-date>
  <authored-date>2008-05-09T00:53:51-07:00</authored-date>
  <message>Simplified Association Proxy class interfaces

* No longer need to pass in a loader block into ManyToOne::Proxy
* No longer need to pass in a collection to OneToMany::Proxy
* Added OneToMany::Proxy#children= to allow mass-assignment of children
  in one step
* Speced out :dependent option for OneToMany::Proxy</message>
  <tree>b4a166fae1e0f25cfc1f24c823acf874314f879f</tree>
  <committer>
    <name>Dan Kubb</name>
    <email>dan.kubb@autopilotmarketing.com</email>
  </committer>
</commit>
