Module: DataMapper::Constraints::Relationship::OneToMany

### Home Classes Methods

### In Files

- lib/data_mapper/constraints/relationship/one_to_many.rb

### Methods

- ::new
- #enforce_destroy_constraint

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Constraints
- DataMapper::Constraints::Adapters
- DataMapper::Constraints::Adapters::AbstractAdapter
- DataMapper::Constraints::Adapters::DataObjectsAdapter
- DataMapper::Constraints::Adapters::DataObjectsAdapter::SQL
- DataMapper::Constraints::Adapters::Extension
- DataMapper::Constraints::Adapters::MysqlAdapter
- DataMapper::Constraints::Adapters::MysqlAdapter::SQL
- DataMapper::Constraints::Adapters::OracleAdapter
- DataMapper::Constraints::Adapters::PostgresAdapter
- DataMapper::Constraints::Adapters::SqliteAdapter
- DataMapper::Constraints::Adapters::SqlserverAdapter
- DataMapper::Constraints::Migrations
- DataMapper::Constraints::Migrations::Model
- DataMapper::Constraints::Migrations::Relationship
- DataMapper::Constraints::Migrations::Relationship::ManyToOne
- DataMapper::Constraints::Migrations::SingletonMethods
- DataMapper::Constraints::Relationship
- DataMapper::Constraints::Relationship::ManyToMany
- DataMapper::Constraints::Relationship::OneToMany
- DataMapper::Constraints::Resource

No matching classes.

# DataMapper::Constraints::Relationship::OneToMany

### Attributes

constraint[R]

### Public Class Methods

new(*args) click to toggle source

Adds the delete constraint options to a relationship

@param params [*ARGS] Arguments passed to Relationship#initialize

@return [nil]

@api private

    # File lib/data_mapper/constraints/relationship/one_to_many.rb, line 38
    def initialize(*args)
      super
      set_constraint
      assert_valid_constraint
    end

### Public Instance Methods

enforce_destroy_constraint(resource) click to toggle source

@api private

    # File lib/data_mapper/constraints/relationship/one_to_many.rb, line 9
    def enforce_destroy_constraint(resource)
      return true unless association = get(resource)

      constraint = self.constraint

      case constraint
      when :protect
        Array(association).empty?
      when :destroy, :destroy!
        association.__send__(constraint)
      when :set_nil
        Array(association).all? do |resource|
          resource.update(inverse => nil)
        end
      when :skip
        true  # do nothing
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.