<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -2,7 +2,7 @@ module App
   class InstanceNotFoundException &lt; StandardError; end
 
   class DataContainer
-
+    include Namespacing
     #
     # Initialize a new DataContainer from a list of naked Sequel record hashes
     #
@@ -159,13 +159,17 @@ module App
       end
 
       # Fetch the entities
-      entities = ns()::Entity.filter(:id =&gt; extra_ids).
+      entities = ns()::Entity.filter(:id =&gt; extra_ids.to_a).
         select(:id, :title, :kind).all
 
       entities.each do |e|
         @extra_entities[e[:id]] = e if e
       end
     end
+
+    def dirty?
+      !@dirty.empty?
+    end
   
   end
 </diff>
      <filename>app/models/app/data_container.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,7 +35,7 @@ module App
       
       set_title_value()
 
-      return super if @data_container.empty? # if no fieldlets, save the normal way
+      return super if !@data_container.dirty? # if no fieldlets, save the normal way
       #return false if !self.valid?
       self.db.transaction do
         super #call for the inherited save action - saves the entity
@@ -53,24 +53,7 @@ module App
       # TODO HOOK API
       self[:title] = &quot;Title&quot;
     end
-	 	
-    ##
-    # Overides the valid? method of Sequel::Model
-    #
-    # @return [Boolean] true if the entity is valid
-    #
-    def valid?
-      @valid ||= @fields_container.valid?
-    end
- 	  
-    ##
-    # Overides the errors method of Sequel::Model
-    #
-    # @return [Array] of errors
-    def errors
-      @fields_container.errors
-    end
-	 	
+		
 	 	
     ##
     # Generates a random 64bit integer for usage as a primary key for entities</diff>
      <filename>app/models/app/entity/writing.rb</filename>
    </modified>
    <modified>
      <diff>@@ -139,9 +139,9 @@ module App
 
       return false if changed.empty?
       
-      save_duplication!
+      #save_duplication!
 			
-      self.each do |fieldlet|
+      @fieldlets.each do |fid, fieldlet|
         fieldlet[:instance_id] = @instance_id
         # set entity id for the new fieldlets
         fieldlet[:entity_id] = @entity[:id]
@@ -174,19 +174,21 @@ module App
         @new ? create_duplicate() : update_duplicate()
       end
     end
-		
+
+    public
     ##
     # Remove the duplicates if the field is duplicated, delete the field instance
     #
     #
     def destroy
-      destroy_duplicate() if self.class::DUPLICATION
+      #destroy_duplicate() if self.class::DUPLICATION
 
       ns()::Fieldlet.filter(:entity_id =&gt; @entity[:id],
         :instance_id =&gt; @instance_id).delete
 				
       return true
     end
+    
 		
     # == ClassMethods
     private</diff>
      <filename>app/models/app/field.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@ module App
   class DuplicantNotFoundException &lt; StandardError; end
   class DuplicantKindMismatchException &lt; StandardError; end
 
-	class Field
+  class Field
 
     def create_duplicate()
       duplicant_field = get_target_field()
@@ -32,167 +32,167 @@ module App
 
 
 
-		# InstanceMethods
-		##
-		# Checks if the linked entity has changed, and we need to delete the duplicates
-		# and recreate them for the new entity
-		#
-		# @return [Boolean] true if the duplicant has changed
-		def duplicant_changed? 
+    # InstanceMethods
+    ##
+    # Checks if the linked entity has changed, and we need to delete the duplicates
+    # and recreate them for the new entity
+    #
+    # @return [Boolean] true if the duplicant has changed
+    def duplicant_changed?
       @old_duplicant_id &amp;&amp; @duplicant_id &amp;&amp; @duplicant_id != @old_duplicant_id
-		end
+    end
 
 
 
 
 
-		##
-		# Delete the duplicates for the given duplicant
-		#
-		# @param [App::Entity] duplicant (optional)
-		#
-		def destroy_duplicate(duplicant = self.duplicant())
-			ns()::Fieldlet.filter(:instance_id =&gt; self.instance_id(), 
-														:entity_id =&gt; duplicant[:id]).delete
-		end
+    ##
+    # Delete the duplicates for the given duplicant
+    #
+    # @param [App::Entity] duplicant (optional)
+    #
+    def destroy_duplicate(duplicant = self.duplicant())
+      ns()::Fieldlet.filter(:instance_id =&gt; self.instance_id(),
+        :entity_id =&gt; duplicant[:id]).delete
+    end
 
 
 
 
 
 
-		##
-		# Updates the duplicants for the given field instance
-		#
-		# @param [Fixnum] instance_id 64bit instance_id to act upon
-		#
-		# === Notes
-		# * If the duplicant entity has changed, we need to delete the currently
-		#   duplicated instance from the older linked duplicant, and create new
-		#   duplicated instance for the new entity
-		#
-		# * If the duplicant hasn't changed, we only update the duplicated instance's
-		#   fieldlets and call #save_changes @see set_duplicants_values!
-		def update_duplicates!(instance_id)
-			if duplicant_changed? 
-				destroy_duplicates!(self.link_fieldlet.old_entity)
-				create_duplicates!(instance_id)
-				return
-			end
-			set_duplicants_values!(instance_id)
-			@duplicated_fieldlets.each{|f| f.new? ? f.save : f.save_changes}
-		end
+    ##
+    # Updates the duplicants for the given field instance
+    #
+    # @param [Fixnum] instance_id 64bit instance_id to act upon
+    #
+    # === Notes
+    # * If the duplicant entity has changed, we need to delete the currently
+    #   duplicated instance from the older linked duplicant, and create new
+    #   duplicated instance for the new entity
+    #
+    # * If the duplicant hasn't changed, we only update the duplicated instance's
+    #   fieldlets and call #save_changes @see set_duplicants_values!
+    def update_duplicates!(instance_id)
+      if duplicant_changed?
+        destroy_duplicates!(self.link_fieldlet.old_entity)
+        create_duplicates!(instance_id)
+        return
+      end
+      set_duplicants_values!(instance_id)
+      @duplicated_fieldlets.each{|f| f.new? ? f.save : f.save_changes}
+    end
 		
-		##
-		# Creates the duplicants for the given field instance
-		#
-		# @param [Fixnum] instance_id 64bit instance_id to act upon
+    ##
+    # Creates the duplicants for the given field instance
+    #
+    # @param [Fixnum] instance_id 64bit instance_id to act upon
     #
     #
-		def create_duplicates!(instance)
-			set_duplicants_values!(instance,true) # true for creating duplicates
-			@duplicated_fieldlets.each{|f| f.save}
-		end
+    def create_duplicates!(instance)
+      set_duplicants_values!(instance,true) # true for creating duplicates
+      @duplicated_fieldlets.each{|f| f.save}
+    end
 		
-		##
-		# Updates the duplicants for the given field instance
-		#
-		# @param [Fixnum] instance_id 64bit instance_id to act upon
-		# @param [Boolean] force_create true for creating fieldlets, false for
-		#                  updating
-		#
-		#
+    ##
+    # Updates the duplicants for the given field instance
+    #
+    # @param [Fixnum] instance_id 64bit instance_id to act upon
+    # @param [Boolean] force_create true for creating fieldlets, false for
+    #                  updating
+    #
+    #
 		 
-		def set_duplicants_values!(instance_id, force_create = false)
-			@duplicated_fieldlets = []
+    def set_duplicants_values!(instance_id, force_create = false)
+      @duplicated_fieldlets = []
 			
-			fieldlets = self.all_fieldlets
-			target_fieldlet_ids = self.duplicants_fieldlet_ids
+      fieldlets = self.all_fieldlets
+      target_fieldlet_ids = self.duplicants_fieldlet_ids
 
-			if target_fieldlet_ids.size != fieldlets.size
-				raise &quot;duplicated fields should match!!&quot; 
-			end
+      if target_fieldlet_ids.size != fieldlets.size
+        raise &quot;duplicated fields should match!!&quot;
+      end
 			
-			fieldlets.each_with_index do |fieldlet,i|
-				next if !fieldlet.value? #skip if the fieldlet is null
+      fieldlets.each_with_index do |fieldlet,i|
+        next if !fieldlet.value? #skip if the fieldlet is null
 			
-				# get the original values
-				values = fieldlet.values.dup #dup because hashes are mutable
+        # get the original values
+        values = fieldlet.values.dup #dup because hashes are mutable
 				
-				# overide the kind and the entity_id values
-				values.merge!(:entity_id =&gt; duplicant.pk, 
-											:kind =&gt; target_fieldlet_ids[i].to_i(16), 
-											:instance_id_id =&gt; instance_id)
+        # overide the kind and the entity_id values
+        values.merge!(:entity_id =&gt; duplicant.pk,
+          :kind =&gt; target_fieldlet_ids[i].to_i(16),
+          :instance_id_id =&gt; instance_id)
 				
-				# if we're duplicating the link fieldlet, we need to revesrse it on the 
-				# duplicated version
-				if self.class::LINK_FIELDLET == fieldlet.class::IDENTIFIER
-					values.merge!(:int_value =&gt; @entity[:id])
-				end
+        # if we're duplicating the link fieldlet, we need to revesrse it on the
+        # duplicated version
+        if self.class::LINK_FIELDLET == fieldlet.class::IDENTIFIER
+          values.merge!(:int_value =&gt; @entity[:id])
+        end
 				
-				# now will create the fieldlet instance_ids
-					if (fieldlet.new? || force_create)
-						target_fieldlet = ns()::Fieldlet.new
-						target_fieldlet.values.merge!(values)
-					else
-						target_fieldlet = ns()::Fieldlet.load(values)
+        # now will create the fieldlet instance_ids
+        if (fieldlet.new? || force_create)
+          target_fieldlet = ns()::Fieldlet.new
+          target_fieldlet.values.merge!(values)
+        else
+          target_fieldlet = ns()::Fieldlet.load(values)
 					
-						target_fieldlet.set_changed_columns(fieldlet.changed_columns)
-					end
-					@duplicated_fieldlets &lt;&lt; target_fieldlet
-			end
+          target_fieldlet.set_changed_columns(fieldlet.changed_columns)
+        end
+        @duplicated_fieldlets &lt;&lt; target_fieldlet
+      end
 			
-			return @duplicated_fieldlets
-		end
+      return @duplicated_fieldlets
+    end
 		
 		
-		##
-		# Returns a list of fieldlet ids of the mirroring duplicant field
-		#
-		# @return [Array[String]] the hex encoded fieldlet ids
-		#
-		def duplicants_fieldlet_ids
-			self.duplicant_field::FIELDLET_IDS
-		end
+    ##
+    # Returns a list of fieldlet ids of the mirroring duplicant field
+    #
+    # @return [Array[String]] the hex encoded fieldlet ids
+    #
+    def duplicants_fieldlet_ids
+      self.duplicant_field::FIELDLET_IDS
+    end
 		
-		##
-		# Returns the Field class of the duplicant entity, which mirrors this instance field
-		# 
-		# @return [Class] the duplicant field class
-		#
-		#
-		def duplicant_field
-			@duplicant_field ||= self.class::DUPLICATION[self.duplicant.class]
-		end
+    ##
+    # Returns the Field class of the duplicant entity, which mirrors this instance field
+    #
+    # @return [Class] the duplicant field class
+    #
+    #
+    def duplicant_field
+      @duplicant_field ||= self.class::DUPLICATION[self.duplicant.class]
+    end
 		
-		##
-		# Returns the *current* linked entity to this instance
-		# The duplicant is the entity to which the link_fieldlet is pointing to *currently*
-		#
-		# @return [App::Entity] the linked entity
-		#
-		# === Notes
-		# * the @old_duplicant instance variable is filled upon loading of the entity, with the pointed
-		#   entity of the link, currently stored in the DB.
-		#
-		# * if we have no dupliant, we'll use the @old_duplicant
-		#
-		def duplicant
-			@duplicant ||= self.link_fieldlet.entity
-			@duplicant || @old_duplicant
-		end
+    ##
+    # Returns the *current* linked entity to this instance
+    # The duplicant is the entity to which the link_fieldlet is pointing to *currently*
+    #
+    # @return [App::Entity] the linked entity
+    #
+    # === Notes
+    # * the @old_duplicant instance variable is filled upon loading of the entity, with the pointed
+    #   entity of the link, currently stored in the DB.
+    #
+    # * if we have no dupliant, we'll use the @old_duplicant
+    #
+    def duplicant
+      @duplicant ||= self.link_fieldlet.entity
+      @duplicant || @old_duplicant
+    end
 		
-		##
-		# Return the fieldlet with the type that was defined as the link fieldlet of the field
-		# link fieldlet connects the field to the other side of the link
-		#
-		# @return [App::Fieldlet] the linked fieldlet
-		#
-		def link_fieldlet
-			@fieldlets[self.class::LINK_FIELDLET]
-		end
+    ##
+    # Return the fieldlet with the type that was defined as the link fieldlet of the field
+    # link fieldlet connects the field to the other side of the link
+    #
+    # @return [App::Fieldlet] the linked fieldlet
+    #
+    def link_fieldlet
+      @fieldlets[self.class::LINK_FIELDLET]
+    end
 		
-		#end InstanceMethods
+    #end InstanceMethods
 
-	end
+  end
 end
\ No newline at end of file</diff>
      <filename>app/models/app/field/field_duplication.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@
 #
 
 module Fieldlets
-	class DateTimeFieldlet &lt; App::Fieldlet
+  class DateTimeFieldlet &lt; App::Fieldlet
     HAS_EXTRA = false
 
     def self.to_output(flet, dc)
@@ -21,5 +21,8 @@ module Fieldlets
       self[:string_value] = value.to_s
     end
 
-	end
+    def value
+      self[:string_value]
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/nifty_base_fieldlets/date_time_fieldlet.rb</filename>
    </modified>
    <modified>
      <diff>@@ -33,6 +33,10 @@ module Fieldlets
       self[:int_value] = value.to_i(16)
     end
 
+    def value
+      &quot;%016x&quot; % self[:int_value]
+    end
+
 
     
 	end</diff>
      <filename>lib/nifty_base_fieldlets/link_fieldlet.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,9 +6,9 @@
 #
 
 module Fieldlets
-	class NumberFieldlet &lt; App::Fieldlet
+  class NumberFieldlet &lt; App::Fieldlet
     HAS_EXTRA = false
-		# included hook
+    # included hook
 
     def self.to_output(flet, dc)
       flet[:int_value]
@@ -20,5 +20,9 @@ module Fieldlets
     def value=(value)
       self[:int_value] = value.to_i
     end
-	end
+
+    def value
+      self[:int_value]
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/nifty_base_fieldlets/number_fieldlet.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@
 #
 
 module Fieldlets
-	class StringFieldlet &lt; App::Fieldlet
+  class StringFieldlet &lt; App::Fieldlet
     HAS_EXTRA = false
 
     def self.to_output(flet, dc)
@@ -19,5 +19,8 @@ module Fieldlets
       self[:string_value] = value
     end
 
-	end
+    def value
+      self[:string_value]
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/nifty_base_fieldlets/string_fieldlet.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@
 #
 
 module Fieldlets
-	class TextFieldlet &lt; App::Fieldlet
+  class TextFieldlet &lt; App::Fieldlet
     HAS_EXTRA = false
 
     def self.to_output(flet, dc)
@@ -18,5 +18,9 @@ module Fieldlets
     def value=(value)
       self[:text_value] = value
     end
-	end
+
+    def value
+      self[:text_value]
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/nifty_base_fieldlets/text_fieldlet.rb</filename>
    </modified>
    <modified>
      <diff>@@ -39,14 +39,14 @@ STOREY =  { # Storey Publishing
 
 describe &quot;Entity updates&quot; do
   def match_instance_data(instance, data)
-    instance.each do |id, value|
-      value.should == data[&quot;%016&quot; % id]
+    instance.fieldlets.each do |id, flet|
+      flet.value.should == data[&quot;%016x&quot; % id]
     end
 
   end
 
   def save_reload_and_match(data)
-    @entity.save
+    @entity.save_changes
 
     instance_id = @entity.data_container.dirty.values.first.instance_id
     
@@ -82,14 +82,14 @@ describe &quot;Entity updates&quot; do
 
     instance_id = instance.instance_id
 
-    @entity.save
+    @entity.save_changes
 
 
     # reload
     @entity = ENTITY.find_with_fieldlets(STOREY[:id])
 
     l = lambda{@entity.data_container.get_insance(instance_id)}
-    l.should_raise(InstanceNotFoundException)
+    l.should raise(App::InstanceNotFoundException)
   end
   
   it &quot;should Edit instances correctly&quot; do</diff>
      <filename>spec/app/entity_update_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>811396edad22fd6d980ba6766a06c3d54fa6b3ea</id>
    </parent>
  </parents>
  <author>
    <name>shlomiatar</name>
    <email>shlomiatar@gmail.com</email>
  </author>
  <url>http://github.com/shlomiatar/nifty-vm/commit/4fe1be8b1e9005b19720a9375b245d59783f3759</url>
  <id>4fe1be8b1e9005b19720a9375b245d59783f3759</id>
  <committed-date>2009-05-07T07:47:57-07:00</committed-date>
  <authored-date>2009-05-07T07:47:57-07:00</authored-date>
  <message>Update-related changes</message>
  <tree>3fbbcf46d589fbc14014f08778269dec0b270447</tree>
  <committer>
    <name>shlomiatar</name>
    <email>shlomiatar@gmail.com</email>
  </committer>
</commit>
