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
38:         def initialize(*args)
39:           super
40:           set_constraint
41:           assert_valid_constraint
42:         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
 9:         def enforce_destroy_constraint(resource)
10:           return true unless association = get(resource)
11: 
12:           constraint = self.constraint
13: 
14:           case constraint
15:           when :protect
16:             Array(association).empty?
17:           when :destroy, :destroy!
18:             association.__send__(constraint)
19:           when :set_nil
20:             Array(association).all? do |resource|
21:               resource.update(inverse => nil)
22:             end
23:           when :skip
24:             true  # do nothing
25:           end
26:         end

Private Instance Methods

assert_valid_constraint() click to toggle source

Checks that the constraint type is appropriate to the relationship

@param [Fixnum] cardinality

  cardinality of relationship

@param [Symbol] name

  name of relationship to evaluate constraint of

@param [Hash] options

  options hash

@option *args :constraint[Symbol]

  one of VALID_CONSTRAINT_VALUES

@raise ArgumentError

  if @option :constraint is not one of VALID_CONSTRAINT_VALUES

@return [Undefined]

@api semipublic

    # File lib/data_mapper/constraints/relationship/one_to_many.rb, line 66
66:         def assert_valid_constraint
67:           return unless @constraint
68: 
69:           unless VALID_CONSTRAINT_VALUES.include?(@constraint)
70:             raise ArgumentError, ":constraint option must be one of #{VALID_CONSTRAINT_VALUES.to_a.join(', ')}"
71:           end
72:         end
set_constraint() click to toggle source
    # File lib/data_mapper/constraints/relationship/one_to_many.rb, line 44
44:         def set_constraint
45:           @constraint = @options.fetch(:constraint, :protect) || :skip
46:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.