Sha256: 7d59cfd2b0f45faeee2d8507c9f9f6d8fb33fb4e8d9215770397977ec29584bf

Contents?: true

Size: 1.51 KB

Versions: 34

Compression:

Stored size: 1.51 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)
          unique_query = object.as(:self).unique_nodes(self, :self, :n, :other_rel)
          unique_query.query.optional_match('(n)-[r]-()').delete(:n, :r).exec if unique_query
        end

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

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

        # End callback methods
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
neo4j-9.6.2 lib/neo4j/active_node/dependent/association_methods.rb
activegraph-10.0.0.pre.alpha.11 lib/neo4j/active_node/dependent/association_methods.rb
activegraph-10.0.0.pre.alpha.10 lib/neo4j/active_node/dependent/association_methods.rb
activegraph-10.0.0.pre.alpha.9 lib/neo4j/active_node/dependent/association_methods.rb
activegraph-10.0.0.pre.alpha.8 lib/neo4j/active_node/dependent/association_methods.rb
activegraph-10.0.0.pre.alpha.7 lib/neo4j/active_node/dependent/association_methods.rb
activegraph-10.0.0.pre.alpha.6 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-10.0.0.pre.alpha.5 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-10.0.0.pre.alpha.4 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-10.0.0.pre.alpha.3 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-10.0.0.pre.alpha.2 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-10.0.0.pre.alpha.1 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.6.1 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.6.0 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.5.3 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.5.2 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.5.0 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.4.0 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.3.0 lib/neo4j/active_node/dependent/association_methods.rb
neo4j-9.2.4 lib/neo4j/active_node/dependent/association_methods.rb