Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved to one_to_many.rb as Proxy.

  • Loading branch information...
commit 682e5c4ae2c17ae13418f010290776654d05be68 1 parent a2e7c57
@david david authored
Showing with 0 additions and 75 deletions.
  1. +0 −75 lib/data_mapper/associations/parent_to_child_association.rb
View
75 lib/data_mapper/associations/parent_to_child_association.rb
@@ -1,75 +0,0 @@
-require 'forwardable'
-
-module DataMapper
- module Associations
- class ParentToChildAssociation
- extend Forwardable
- include Enumerable
-
- def_instance_delegators :entries, :[], :size, :length, :first, :last
-
- def loaded?
- !defined?(@children_resources)
- end
-
- def children
- @children_resources ||= @children_loader.call
- end
-
- def save
- @dirty_children.each do |child_resource|
- @relationship.attach_parent(child_resource, @parent_resource)
- repository(@relationship.repository_name).save(child_resource)
- end
- end
-
- def push(*child_resources)
- child_resources.each do |child_resource|
- children << child_resource
-
- if @parent_resource.new_record?
- @dirty_children << child_resource
- else
- @relationship.attach_parent(child_resource, @parent_resource)
- repository(@relationship.repository_name).save(child_resource)
- end
- end
- self
- end
-
- alias << push
-
- def delete(child_resource)
- deleted_resource = children.delete(child_resource)
- begin
- @relationship.attach_parent(deleted_resource, nil)
- repository(@relationship.repository_name).save(deleted_resource)
- rescue
- children << child_resource
- raise
- end
- end
-
- def clear
- each { |child_resource| delete(child_resource) }
- end
-
- def each(&block)
- children.each { |child_resource| yield child_resource }
- self
- end
-
- private
-
- def initialize(relationship, parent_resource, &children_loader)
-# raise ArgumentError, "+relationship+ should be a DataMapper::Association::Relationship, but was #{relationship.class}", caller unless Relationship === relationship
-# raise ArgumentError, "+parent_resource+ should be a DataMapper::Resource, but was #{parent_resource.class}", caller unless Resource === parent_resource
-
- @relationship = relationship
- @parent_resource = parent_resource
- @children_loader = children_loader
- @dirty_children = []
- end
- end # class ParentToChildAssociation
- end # module Associations
-end # module DataMapper
Please sign in to comment.
Something went wrong with that request. Please try again.