lib/api_resource/associations.rb in api_resource-0.3.7 vs lib/api_resource/associations.rb in api_resource-0.3.8

- old
+ new

@@ -24,10 +24,16 @@ "Can't include Associations without AssociationActivation" ) end class_attribute :related_objects + attr_accessor :assoc_attributes + + define_method(:assoc_attributes) do + @assoc_attributes ||= Hash.new + end + self.clear_related_objects # we need to add an inherited method here, but it can't happen # until after this module in included/extended, so it's in its own # little mini module @@ -153,10 +159,10 @@ def define_association_as_attribute(assoc_type, assoc_name) # set up dirty tracking for associations self.class_eval <<-EOE, __FILE__, __LINE__ + 1 def #{assoc_name} - self.attributes[:#{assoc_name}] ||= #{self.association_types[assoc_type.to_sym].to_s.classify}ObjectProxy.new(self.association_class_name('#{assoc_name}'), nil, self) + self.assoc_attributes[:#{assoc_name}] ||= (self.attributes[:#{assoc_name}] || #{self.association_types[assoc_type.to_sym].to_s.classify}ObjectProxy.new(self.association_class_name('#{assoc_name}'), nil, self)) end def #{assoc_name}=(val) # get old internal object old_internal_object = self.#{assoc_name}.internal_object self.#{assoc_name}.internal_object = val \ No newline at end of file