module ActiveGraph::Node::Query

Helper methods to return ActiveGraph::Core::Query objects. A query object can be used to successively build a cypher query

person.query_as(:n).match('n-[:friend]-o').return(o: :name) # Return the names of all the person's friends

Public Instance Methods

as(node_var) click to toggle source

Starts a new QueryProxy with the starting identifier set to the given argument and QueryProxy source_object set to the node instance. This method does not exist within QueryProxy and can only be used to start a new chain.

@example Start a new QueryProxy chain with the first identifier set manually

# Generates: MATCH (s:`Student`), (l:`Lesson`), s-[rel1:`ENROLLED_IN`]->(l:`Lesson`) WHERE ID(s) = $neo_id_17963
student.as(:s).lessons(:l)

@param [String, Symbol] node_var The identifier to use within the QueryProxy object @return [ActiveGraph::Node::Query::QueryProxy]

   # File lib/active_graph/node/query.rb
31 def as(node_var)
32   self.class.query_proxy(node: node_var, source_object: self).match_to(self)
33 end
query_as(node_var) click to toggle source

Returns a Query object with the current node matched the specified variable name

@example Return the names of all of Mike's friends

# Generates: MATCH (mike:Person), mike-[:friend]-friend WHERE ID(mike) = 123 RETURN friend.name
mike.query_as(:mike).match('mike-[:friend]-friend').return(friend: :name)

@param node_var [Symbol, String] The variable name to specify in the query @return [ActiveGraph::Core::Query]

   # File lib/active_graph/node/query.rb
18 def query_as(node_var)
19   self.class.query_as(node_var, false).where("ID(#{node_var})" => self.neo_id)
20 end