Sha256: 766f0d8e6bb89c04e14954ed7bea6f28b276d5f5f31dc8a66e06df05e1f795a6

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

module DataMapper
  module Associations
    
    module ManyToOne
      
      class Proxy
        
        def save
          
          return false if @parent.nil?
          
          # original dm-core-0.9.11 code:
          # return true unless parent.new_record?
          
          # and the backwards compatible extension to it (allows update of belongs_to model)
          if !parent.new_record? && !@relationship.child_model.autosave_associations.key?(@relationship.name)
            return true
          end

          @relationship.with_repository(parent) do
            result = parent.marked_for_destruction? ? parent.destroy : parent.save
            @relationship.child_key.set(@child, @relationship.parent_key.get(parent)) if result
            result
          end
          
        end
        
      end
      
    end
    
    
    module OneToMany
    
      class Proxy
        
        private
        
        def save_resource(resource, parent = @parent)
          @relationship.with_repository(resource) do |r|
            if parent.nil? && resource.model.respond_to?(:many_to_many)
              resource.destroy
            else
              @relationship.attach_parent(resource, parent)
              resource.marked_for_destruction? ? resource.destroy : resource.save
            end
          end
        end
        
      end
      
    end
    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snusnu-dm-accepts_nested_attributes-0.0.1 lib/dm-accepts_nested_attributes/associations.rb
snusnu-dm-accepts_nested_attributes-0.0.2 lib/dm-accepts_nested_attributes/associations.rb
snusnu-dm-accepts_nested_attributes-0.0.3 lib/dm-accepts_nested_attributes/association_proxies.rb
snusnu-dm-accepts_nested_attributes-0.0.4 lib/dm-accepts_nested_attributes/association_proxies.rb
snusnu-dm-accepts_nested_attributes-0.0.5 lib/dm-accepts_nested_attributes/association_proxies.rb
snusnu-dm-accepts_nested_attributes-0.0.6 lib/dm-accepts_nested_attributes/association_proxies.rb