<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>Rakefile</filename>
    </added>
    <added>
      <filename>spec/spec.opts</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -42,6 +42,7 @@ module CouchPotato
     def destroy
       run_callbacks(:before_destroy)
       self.class.db.delete self
+      destroy_dependent_objects
       run_callbacks(:after_destroy)
       self._id = nil
       self._rev = nil
@@ -113,6 +114,12 @@ module CouchPotato
       end
     end
     
+    def destroy_dependent_objects
+      self.class.properties.each do |property|
+        property.destroy(self)
+      end
+    end
+    
     module ClassMethods
       
       def create!(attributes = {})</diff>
      <filename>lib/couch_potato/persistence.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@ module CouchPotato
     class BelongsToProperty
       attr_accessor :name
       
-      def initialize(owner_clazz, name)
+      def initialize(owner_clazz, name, options = {})
         self.name = name
         accessors =  &lt;&lt;-ACCESSORS
           def #{name}
@@ -23,6 +23,10 @@ module CouchPotato
         
       end
       
+      def destroy(object)
+        
+      end
+      
       def build(object, json)
         object.send &quot;#{name}_id=&quot;, json[&quot;#{name}_id&quot;]
       end
@@ -32,8 +36,9 @@ module CouchPotato
       end
       
       def item_class_name
-        @name.to_s.singularize.capitalize
+        @name.to_s.singularize.camelcase
       end
+      
     end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/couch_potato/persistence/belongs_to_property.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ module CouchPotato
         @owner_id_attribute_name = owner_id_attribute_name
       end
       
-      def build(attributes)
+      def build(attributes = {})
         item = @item_class.new(attributes)
         self.&lt;&lt; item
         item.position = self.size if item.respond_to?(:position=)
@@ -21,6 +21,18 @@ module CouchPotato
         item
       end
       
+      def create(attributes = {})
+        item = build(attributes)
+        item.save
+        item
+      end
+      
+      def create!(attributes = {})
+        item = build(attributes)
+        item.save!
+        item
+      end
+      
       def items
         if @items.nil?
           @items = Finder.new.find @item_class, @owner_id_attribute_name =&gt; owner_id
@@ -35,6 +47,19 @@ module CouchPotato
         end
       end
       
+      def destroy
+        @items.each do |item|
+          item.destroy
+        end
+      end
+      
+      def nullify
+        @items.each do |item|
+          item.send &quot;#{@owner_id_attribute_name}=&quot;, nil
+          item.save
+        end
+      end
+      
     end
   end
 end</diff>
      <filename>lib/couch_potato/persistence/external_collection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,10 @@
 module CouchPotato
   module Persistence
     class ExternalHasManyProperty
-      attr_accessor :name
-      def initialize(owner_clazz, name)
+      attr_accessor :name, :dependent
+      def initialize(owner_clazz, name, options = {})
         @name, @owner_clazz = name, owner_clazz
+        @dependent = options[:dependent] || :nullify
         getter =  &lt;&lt;-ACCESORS
           def #{name}
             @#{name} ||= CouchPotato::Persistence::ExternalCollection.new(#{item_class_name}, :#{owner_clazz.name.underscore}_id)
@@ -19,12 +20,21 @@ module CouchPotato
       end
       
       def save(object)
+        object.send(name).owner_id = object._id
         object.send(name).each do |item|
           item.send(&quot;#{@owner_clazz.name.underscore}_id=&quot;, object.id)
           item.save
         end
       end
       
+      def destroy(object)
+        if dependent == :destroy
+          object.send(name).destroy
+        else
+          object.send(name).nullify
+        end
+      end
+      
       def build(object, json)
         collection = ExternalCollection.new(item_class_name.constantize, &quot;#{@owner_clazz.name.underscore}_id&quot;)
         collection.owner_id = object.id
@@ -38,7 +48,7 @@ module CouchPotato
       private
       
       def item_class_name
-        @name.to_s.singularize.capitalize
+        @name.to_s.singularize.camelcase
       end
     end
   end</diff>
      <filename>lib/couch_potato/persistence/external_has_many_property.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 class InlineHasManyProperty
   attr_accessor :name
   
-  def initialize(owner_clazz, name)
+  def initialize(owner_clazz, name, options = {})
     @name = name
     getter =  &lt;&lt;-GETTER
       def #{name}
@@ -26,9 +26,13 @@ class InlineHasManyProperty
     json[name.to_s] = object.send(name)
   end
   
+  def destroy(object)
+    
+  end
+  
   private
   
   def item_class_name
-    @name.to_s.singularize.capitalize
+    @name.to_s.singularize.camelcase
   end
 end
\ No newline at end of file</diff>
      <filename>lib/couch_potato/persistence/inline_has_many_property.rb</filename>
    </modified>
    <modified>
      <diff>@@ -22,7 +22,8 @@ module CouchPotato
         end
         
         def property(name, options = {})
-          properties &lt;&lt; (options[:class] || SimpleProperty).new(self, name)
+          clazz = options.delete(:class)
+          properties &lt;&lt; (clazz || SimpleProperty).new(self, name, options)
         end
 
         def belongs_to(name)
@@ -30,11 +31,8 @@ module CouchPotato
         end
 
         def has_many(name, options = {})
-          if(options[:stored] == :inline)
-            property name, :class =&gt; InlineHasManyProperty
-          else
-            property name, :class =&gt; ExternalHasManyProperty
-          end
+          stored = options.delete(:stored)
+          property name, options.merge(:class =&gt; (stored == :inline ? InlineHasManyProperty : ExternalHasManyProperty))
         end
       end
     end</diff>
      <filename>lib/couch_potato/persistence/properties.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,7 @@ module CouchPotato
     class SimpleProperty
       attr_accessor :name
       
-      def initialize(owner_clazz, name)
+      def initialize(owner_clazz, name, options = {})
         self.name = name
         owner_clazz.send :attr_accessor, name
       end
@@ -16,6 +16,10 @@ module CouchPotato
         
       end
       
+      def destroy(object)
+        
+      end
+      
       def serialize(json, object)
         json[name] = object.send name
       end</diff>
      <filename>lib/couch_potato/persistence/simple_property.rb</filename>
    </modified>
    <modified>
      <diff>@@ -21,5 +21,4 @@ describe 'destroy' do
     }.should raise_error(RestClient::ResourceNotFound)
   end
   
-  it &quot;should destroy all dependent objects&quot;
 end
\ No newline at end of file</diff>
      <filename>spec/destroy_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,6 +37,22 @@ describe 'has_many stored separately' do
     @commenter.comments.first.title.should == 'my title'
   end
   
+  it &quot;should create child objects&quot; do
+    @commenter.save!
+    @commenter.comments.create(:title =&gt; 'my title')
+    @commenter = Commenter.find @commenter._id
+    @commenter.comments.first.class.should == Comment
+    @commenter.comments.first.title.should == 'my title'
+  end
+  
+  it &quot;should create! child objects&quot; do
+    @commenter.save!
+    @commenter.comments.create!(:title =&gt; 'my title')
+    @commenter = Commenter.find @commenter._id
+    @commenter.comments.first.class.should == Comment
+    @commenter.comments.first.title.should == 'my title'
+  end
+  
   it &quot;should add child objects&quot; do
     @commenter.comments &lt;&lt; Comment.new(:title =&gt; 'my title')
     @commenter.comments.first.class.should == Comment
@@ -50,4 +66,41 @@ describe 'has_many stored separately' do
     @commenter.comments.first.class.should == Comment
     @commenter.comments.first.title.should == 'my title'
   end
+  
+  describe &quot;destroying&quot; do
+    
+    class AdminComment
+      include CouchPotato::Persistence
+      belongs_to :admin
+    end
+    
+    class AdminFriend
+      include CouchPotato::Persistence
+      belongs_to :admin
+    end
+    
+    class Admin
+      include CouchPotato::Persistence
+      has_many :admin_comments, :stored =&gt; :separately, :dependent =&gt; :destroy
+      has_many :admin_friends, :stored =&gt; :separately
+    end
+    
+    it &quot;should destroy all dependent objects&quot; do
+      admin = Admin.create!
+      comment = admin.admin_comments.create!
+      id = comment._id
+      admin.destroy
+      lambda {
+        CouchPotato::Persistence.Db.get(id).should
+      }.should raise_error(RestClient::ResourceNotFound)
+    end
+
+    it &quot;should nullify independent objects&quot; do
+      admin = Admin.create!
+      friend = admin.admin_friends.create!
+      id = friend._id
+      admin.destroy
+      AdminFriend.get(id).admin.should be_nil
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>spec/has_many_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e46ff398615c377e505eca2442f13118c1aad915</id>
    </parent>
  </parents>
  <author>
    <name>Alexander Lang</name>
    <email>alex@skywalker.lan</email>
  </author>
  <url>http://github.com/langalex/couch_potato/commit/d11083bcde939a3c8e714727ea0b7d7d75e8eaac</url>
  <id>d11083bcde939a3c8e714727ea0b7d7d75e8eaac</id>
  <committed-date>2008-10-24T04:05:22-07:00</committed-date>
  <authored-date>2008-10-24T04:05:22-07:00</authored-date>
  <message>added dependent destroy, nullify for independent objects, added rakefile for running all specs</message>
  <tree>20da4f0a297817148b75e869b5be07cb515f4864</tree>
  <committer>
    <name>Alexander Lang</name>
    <email>alex@skywalker.lan</email>
  </committer>
</commit>
