QueryProxy

Constants

  • METHODS
  • FIRST
  • LAST

Methods

#<<

To add a relationship for the node for the association on this QueryProxy

+ show/hide code
#==

Does exactly what you would hope. Without it, comparing bobby.lessons == sandy.lessons would evaluate to false because it would be comparing the QueryProxy objects, not the lessons themselves.

+ show/hide code

#[]

+ show/hide code

#_create_relationship

+ show/hide code
#_model_label_string

param [TrueClass, FalseClass] with_labels This param is used by certain QueryProxy methods that already have the neo_id and therefore do not need labels. The @association_labels instance var is set during init and used during association chaining to keep labels out of Cypher queries.

+ show/hide code

#_nodeify!

+ show/hide code
#all_rels_to

Returns all relationships across a QueryProxy chain between a given node or array of nodes and the preceeding link.

+ show/hide code
#as_models

Takes an Array of ActiveNode models and applies the appropriate WHERE clause So for a Teacher model inheriting from a Person model and an Article model if you called .as_models([Teacher, Article]) The where clause would look something like:

WHERE (node_var:Teacher:Person OR node_var:Article)
+ show/hide code
#association

The most recent node to start a QueryProxy chain. Will be nil when using QueryProxy chains on class methods.

+ show/hide code

#base_query

+ show/hide code

#blank?

+ show/hide code
#context

Returns the value of attribute context

+ show/hide code

#count

+ show/hide code

#create

+ show/hide code

#defer_create

+ show/hide code
#delete

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

+ show/hide code
#delete_all

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

+ show/hide code
#delete_all_rels

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

+ show/hide code
#destroy

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

+ show/hide code

#each

+ show/hide code
#each_for_destruction

Used as part of dependent: :destroy and may not have any utility otherwise. It keeps track of the node responsible for a cascading destroy process. but this is not always available, so we require it explicitly.

+ show/hide code
#each_rel

When called at the end of a QueryProxy chain, it will return the resultant relationship objects intead of nodes. For example, to return the relationship between a given student and their lessons:

student.lessons.each_rel do |rel|
+ show/hide code
#each_with_rel

When called at the end of a QueryProxy chain, it will return the nodes and relationships of the last link. For example, to return a lesson and each relationship to a given student:

student.lessons.each_with_rel do |lesson, rel|
+ show/hide code

#empty?

+ show/hide code

#exists?

+ show/hide code

#fetch_result_cache

+ show/hide code
#find

Give ability to call #find on associations to get a scoped find Doesn’t pass through via method_missing because Enumerable has a #find method

+ show/hide code

#find_each

+ show/hide code

#find_in_batches

+ show/hide code
#find_or_create_by

When called, this method returns a single node that satisfies the match specified in the params hash. If no existing node is found to satisfy the match, one is created or associated as expected.

+ show/hide code

#first

+ show/hide code
#first_rel_to

Gives you the first relationship between the last link of a QueryProxy chain and a given node Shorthand for MATCH (start)-[r]-(other_node) WHERE ID(other_node) = #{other_node.neo_id} RETURN r

+ show/hide code

#identity

+ show/hide code

#include?

+ show/hide code
#initialize

QueryProxy is ActiveNode’s Cypher DSL. While the name might imply that it creates queries in a general sense, it is actually referring to <tt>Neo4j::Core::Query</tt>, which is a pure Ruby Cypher DSL provided by the <tt>neo4j-core</tt> gem. QueryProxy provides ActiveRecord-like methods for common patterns. When it’s not handling CRUD for relationships and queries, it provides ActiveNode’s association chaining (student.lessons.teachers.where(age: 30).hobbies) and enjoys long walks on the beach.

It should not ever be necessary to instantiate a new QueryProxy object directly, it always happens as a result of calling a method that makes use of it.

originated. <tt>has_many</tt>) that created this object. QueryProxy objects are evaluated lazily.

+ show/hide code

#inspect

+ show/hide code

#last

+ show/hide code

#length

+ show/hide code
#limit_value

TODO: update this with public API methods if/when they are exposed

+ show/hide code
#match_to

Shorthand for MATCH (start)-[r]-(other_node) WHERE ID(other_node) = #{other_node.neo_id} The node param can be a persisted ActiveNode instance, any string or integer, or nil. When it’s a node, it’ll use the object’s neo_id, which is fastest. When not nil, it’ll figure out the primary key of that model. When nil, it uses 1 = 2 to prevent matching all records, which is the default behavior when nil is passed to where in QueryProxy.

+ show/hide code
#method_missing

QueryProxy objects act as a representation of a model at the class level so we pass through calls This allows us to define class functions for reusable query chaining or for end-of-query aggregation/summarizing

+ show/hide code
#model

The most recent node to start a QueryProxy chain. Will be nil when using QueryProxy chains on class methods.

+ show/hide code
+ show/hide code

#node_identity

+ show/hide code
#node_var

The current node identifier on deck, so to speak. It is the object that will be returned by calling each and the last node link in the QueryProxy chain.

+ show/hide code
#node_where

Since there is a rel_where method, it seems only natural for there to be node_where

+ show/hide code

#offset

+ show/hide code
#optional

A shortcut for attaching a new, optional match to the end of a QueryProxy chain.

+ show/hide code

#optional?

+ show/hide code

#order_by

+ show/hide code

#order_property

+ show/hide code

#params

+ show/hide code
#pluck

For getting variables which have been defined as part of the association chain

+ show/hide code

#print_cypher

+ show/hide code
#query

Like calling #query_as, but for when you don’t care about the variable name

+ show/hide code
#query_as

Build a Neo4j::Core::Query object for the QueryProxy. This is necessary when you want to take an existing QueryProxy chain and work with it from the more powerful (but less friendly) Neo4j::Core::Query. .. code-block:: ruby

student.lessons.query_as(:l).with(‘your cypher here...’)
+ show/hide code
#query_proxy

Returns the value of attribute query_proxy

+ show/hide code

#read_attribute_for_serialization

+ show/hide code

#rel

+ show/hide code

#rel_identity

+ show/hide code
#rel_var

The relationship identifier most recently used by the QueryProxy chain.

+ show/hide code

#rels

+ show/hide code
#rels_to

Returns all relationships across a QueryProxy chain between a given node or array of nodes and the preceeding link.

+ show/hide code
#replace_with

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.

+ show/hide code

#respond_to_missing?

+ show/hide code

#result

+ show/hide code
#scoping

Scope all queries to the current scope.

Comment.where(post_id: 1).scoping do
  Comment.first
end

TODO: unscoped Please check unscoped if you want to remove all previous scopes (including the default_scope) during the execution of a block.

+ show/hide code

#size

+ show/hide code
#source_object

The most recent node to start a QueryProxy chain. Will be nil when using QueryProxy chains on class methods.

+ show/hide code
#start_object

Returns the value of attribute start_object

+ show/hide code
#starting_query

The most recent node to start a QueryProxy chain. Will be nil when using QueryProxy chains on class methods.

+ show/hide code
#to_cypher

Cypher string for the QueryProxy’s query. This will not include params. For the full output, see <tt>to_cypher_with_params</tt>.

+ show/hide code
#to_cypher_with_params

Returns a string of the cypher query with return objects and params

+ show/hide code
#unique_nodes

This will match nodes who only have a single relationship of a given type. It’s used by dependent: :delete_orphans and dependent: :destroy_orphans and may not have much utility otherwise.

+ show/hide code

#with_associations

+ show/hide code

#with_associations_return_clause

+ show/hide code

#with_associations_spec

+ show/hide code