module Sequel::Plugins::AssociationDependencies::ClassMethods

  1. lib/sequel/plugins/association_dependencies.rb

Attributes

association_dependencies [R]

A hash specifying the association dependencies for each model. The keys are symbols indicating the type of action and when it should be executed (e.g. :before_delete). Values are an array of method symbols. For before_nullify, the symbols are remove_all_association methods. For other types, the symbols are association_dataset methods, on which delete or destroy is called.

Public Instance methods

add_association_dependencies(hash)

Add association dependencies to this model. The hash should have association name symbol keys and dependency action symbol values (e.g. albums: :destroy).

[show source]
   # File lib/sequel/plugins/association_dependencies.rb
54 def add_association_dependencies(hash)
55   hash.each do |association, action|
56     raise(Error, "Nonexistent association: #{association}") unless r = association_reflection(association)
57     type = r[:type]
58     raise(Error, "Invalid dependence action type: association: #{association}, dependence action: #{action}") unless DEPENDENCE_ACTIONS.include?(action)
59     raise(Error, "Invalid association type: association: #{association}, type: #{type}") unless time = ASSOCIATION_MAPPING[type]
60     association_dependencies[:"#{time}_#{action}"] << if action == :nullify
61       case type
62       when :one_to_many , :many_to_many
63         [r[:remove_all_method]]
64       when :one_to_one
65         [r[:setter_method], nil]
66       else
67         raise(Error, "Can't nullify many_to_one associated objects: association: #{association}")
68       end
69     else
70       raise(Error, "Can only nullify many_to_many associations: association: #{association}") if type == :many_to_many
71       r[:dataset_method]
72     end
73   end
74 end
freeze()

Freeze association dependencies when freezing model class.

[show source]
   # File lib/sequel/plugins/association_dependencies.rb
77 def freeze
78   @association_dependencies.freeze.each_value(&:freeze)
79 
80   super
81 end