Module: Neo4j::ActiveNode::Query::ClassMethods

Defined in:
lib/neo4j/active_node/query.rb

Instance Method Summary collapse

Instance Method Details

#as(node_var) ⇒ Neo4j::ActiveNode::Query::QueryProxy

Start a new QueryProxy with the starting identifier set to the given argument. This method does not exist within QueryProxy, it can only be called at the class level to create a new QP object. To set an identifier within a QueryProxy chain, give it as the first argument to a chained association.

Examples:

Start a new QueryProxy where the first identifier is set manually.

# Generates: MATCH (s:`Student`), (result_lessons:`Lesson`), s-[rel1:`ENROLLED_IN`]->(result_lessons:`Lesson`)
Student.as(:s).lessons

Parameters:

  • node_var (String, Symbol)

    A string or symbol to use as the starting identifier.

Returns:



70
71
72
# File 'lib/neo4j/active_node/query.rb', line 70

def as(node_var)
  query_proxy(node: node_var, context: self.name)
end

#query_as(var, with_labels = true) ⇒ Neo4j::Core::Query

Returns a Query object with all nodes for the model matched as the specified variable name

an early Cypher match has already filtered results) where including labels will degrade performance.

Examples:

Return the registration number of all cars owned by a person over the age of 30

# Generates: MATCH (person:Person), person-[:owned]-car WHERE person.age > 30 RETURN car.registration_number
Person.query_as(:person).where('person.age > 30').match('person-[:owned]-car').return(car: :registration_number)

Parameters:

  • var (Symbol, String)

    The variable name to specify in the query

  • with_labels (Boolean) (defaults to: true)

    Should labels be used to build the match? There are situations (neo_id used to filter,

Returns:



46
47
48
# File 'lib/neo4j/active_node/query.rb', line 46

def query_as(var, with_labels = true)
  query_proxy.query_as(var, with_labels)
end

#query_proxy(options = {}) ⇒ Object



56
57
58
# File 'lib/neo4j/active_node/query.rb', line 56

def query_proxy(options = {})
  Neo4j::ActiveNode::Query::QueryProxy.new(self, nil, options)
end