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

Defined in:
lib/data_mapper/constraints/relationship/one_to_many.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#constraintObject (readonly)

Returns the value of attribute constraint.



5
6
7
# File 'lib/data_mapper/constraints/relationship/one_to_many.rb', line 5

def constraint
  @constraint
end

Instance Method Details

#enforce_destroy_constraint(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/data_mapper/constraints/relationship/one_to_many.rb', line 8

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 |r|
      r.update(inverse => nil)
    end
  when :skip
    true # do nothing
  end
end