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
@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
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
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.