lib/neo4j/active_node/query.rb in neo4j-4.1.5 vs lib/neo4j/active_node/query.rb in neo4j-5.0.0.rc.1
- old
+ new
@@ -14,43 +14,44 @@
# mike.query_as(:mike).match('mike-[:friend]-friend').return(friend: :name)
#
# @param var [Symbol, String] The variable name to specify in the query
# @return [Neo4j::Core::Query]
def query_as(node_var)
- self.class.query_as(node_var).where("ID(#{node_var})" => self.neo_id)
+ self.class.query_as(node_var, false).where("ID(#{node_var})" => self.neo_id)
end
- # Starts a new QueryProxy with the starting identifier set to the given argument and QueryProxy caller set to the node instance.
+ # 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 [Neo4j::ActiveNode::Query::QueryProxy]
def as(node_var)
- self.class.query_proxy(node: node_var, caller: self).match_to(self)
+ self.class.query_proxy(node: node_var, source_object: self).match_to(self)
end
module ClassMethods
# Returns a Query object with all nodes for the model matched as the specified variable name
#
# @example 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)
#
- # @param var [Symbol, String] The variable name to specify in the query
+ # @param [Symbol, String] var The variable name to specify in the query
+ # @param [Boolean] with_labels Should labels be used to build the match? There are situations (neo_id used to filter,
+ # an early Cypher match has already filtered results) where including labels will degrade performance.
# @return [Neo4j::Core::Query]
- def query_as(var)
- query_proxy.query_as(var)
+ def query_as(var, with_labels = true)
+ query_proxy.query_as(var, with_labels)
end
Neo4j::ActiveNode::Query::QueryProxy::METHODS.each do |method|
- module_eval(%{
- def #{method}(*args)
- self.query_proxy.#{method}(*args)
- end}, __FILE__, __LINE__)
+ define_method(method) do |*args|
+ self.query_proxy.send(method, *args)
+ end
end
def query_proxy(options = {})
Neo4j::ActiveNode::Query::QueryProxy.new(self, nil, options)
end