Sha256: 1b1395562ff462b7205d15e401bc9e7ce2d1b29318d176683df24ba97de485ba

Contents?: true

Size: 1.33 KB

Versions: 19

Compression:

Stored size: 1.33 KB

Contents

module Neo4j
  module ActiveNode
    module Dependent
      module AssociationMethods
        def validate_dependent(value)
          fail ArgumentError, "Invalid dependent value: #{value.inspect}" if not valid_dependent_value?(value)
        end

        def add_destroy_callbacks(model)
          return if dependent.nil?

          model.before_destroy(&method("dependent_#{dependent}_callback"))
        rescue NameError
          raise "Unknown dependent option #{dependent}"
        end

        private

        def valid_dependent_value?(value)
          return true if value.nil?

          self.respond_to?("dependent_#{value}_callback", true)
        end

        # Callback methods
        def dependent_delete_callback(object)
          object.association_query_proxy(name).delete_all
        end

        def dependent_delete_orphans_callback(object)
          object.as(:self).unique_nodes(self, :self, :n, :other_rel).query.delete(:n, :other_rel).exec
        end

        def dependent_destroy_callback(object)
          object.association_query_proxy(name).each_for_destruction(object, &:destroy)
        end

        def dependent_destroy_orphans_callback(object)
          object.as(:self).unique_nodes(self, :self, :n, :other_rel).each_for_destruction(object, &:destroy)
        end

        # End callback methods
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
neo4j-5.0.15 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.14 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.13 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.12 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.11 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.10 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.9 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.8 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.7 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.6 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.5 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.4 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.3 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.2 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.1 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.0 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.0.rc.3 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.0.rc.2 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-5.0.0.rc.1 lib/neo4j/active_node/dependent/association_methods.rb