module Neo4j::ActiveNode::Query::QueryProxyMethodsOfMassUpdating

Public Instance Methods

delete(node) click to toggle source

Deletes the relationship between a node and its last link in the QueryProxy chain. Executed in the database, callbacks will not run.

   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
38 def delete(node)
39   self.match_to(node).query.delete(rel_var).exec
40   clear_source_object_cache
41 end
delete_all(identifier = nil) click to toggle source

Deletes a group of nodes and relationships within a QP chain. When identifier is omitted, it will remove the last link in the chain. The optional argument must be a node identifier. A relationship identifier will result in a Cypher Error @param identifier [String,Symbol] the optional identifier of the link in the chain to delete.

   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
26 def delete_all(identifier = nil)
27   query_with_target(identifier) do |target|
28     begin
29       self.query.with(target).optional_match("(#{target})-[#{target}_rel]-()").delete("#{target}, #{target}_rel").exec
30     rescue Neo4j::Core::CypherSession::CypherError # <=- Seems hacky
31       self.query.delete(target).exec
32     end
33     clear_source_object_cache
34   end
35 end
delete_all_rels() click to toggle source

Deletes the relationships between all nodes for the last step in the QueryProxy chain. Executed in the database, callbacks will not be run.

   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
44 def delete_all_rels
45   return unless start_object && start_object._persisted_obj
46   self.query.delete(rel_var).exec
47 end
destroy(node) click to toggle source

Returns all relationships between a node and its last link in the QueryProxy chain, destroys them in Ruby. Callbacks will be run.

   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
62 def destroy(node)
63   self.rels_to(node).map!(&:destroy)
64   clear_source_object_cache
65 end
replace_with(node_or_nodes) click to toggle source

Deletes the relationships between all nodes for the last step in the QueryProxy chain and replaces them with relationships to the given nodes. Executed in the database, callbacks will not be run.

   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
51 def replace_with(node_or_nodes)
52   nodes = Array(node_or_nodes)
53 
54   self.delete_all_rels
55   nodes.map do |node|
56     node if _create_relation_or_defer(node)
57   end.compact
58   # nodes.each { |node| self << node }
59 end
update_all(updates, params = {}) click to toggle source

Updates some attributes of a group of nodes within a QP chain. The optional argument makes sense only of `updates` is a string. @param [Hash,String] updates An hash or a string of parameters to be updated. @param [Hash] params An hash of parameters for the update string. It's ignored if `updates` is an Hash.

   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
 9 def update_all(updates, params = {})
10   # Move this to ActiveNode module?
11   update_all_with_query(identity, updates, params)
12 end
update_all_rels(updates, params = {}) click to toggle source

Updates some attributes of a group of relationships within a QP chain. The optional argument makes sense only of `updates` is a string. @param [Hash,String] updates An hash or a string of parameters to be updated. @param [Hash] params An hash of parameters for the update string. It's ignored if `updates` is an Hash.

   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
18 def update_all_rels(updates, params = {})
19   fail 'Cannot update rels without a relationship variable.' unless @rel_var
20   update_all_with_query(@rel_var, updates, params)
21 end

Private Instance Methods

clear_source_object_cache() click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
80 def clear_source_object_cache
81   self.source_object.clear_association_cache if self.source_object.respond_to?(:clear_association_cache)
82 end
update_all_with_query(var_name, updates, params) click to toggle source
   # File lib/neo4j/active_node/query/query_proxy_methods_of_mass_updating.rb
69 def update_all_with_query(var_name, updates, params)
70   query = all.query
71 
72   case updates
73   when Hash then query.set(var_name => updates).pluck("count(#{var_name})").first
74   when String then query.set(updates).params(params).pluck("count(#{var_name})").first
75   else
76     fail ArgumentError, "Invalid parameter type #{updates.class} for `updates`."
77   end
78 end