module Neo4j::ActiveRel::Query::ClassMethods

Public Instance Methods

all() click to toggle source

Performs a basic match on the relationship, returning all results. This is not executed lazily, it will immediately return matching objects.

   # File lib/neo4j/active_rel/query.rb
36 def all
37   all_query.pluck(:r1)
38 end
find(id, session = self.neo4j_session) click to toggle source

Returns the object with the specified neo4j id. @param [String,Integer] id of node to find @param [Neo4j::Session] session optional

   # File lib/neo4j/active_rel/query.rb
11 def find(id, session = self.neo4j_session)
12   fail "Unknown argument #{id.class} in find method (expected String or Integer)" if !(id.is_a?(String) || id.is_a?(Integer))
13   find_by_id(id, session)
14 end
find_by_id(key, session = nil) click to toggle source

Loads the relationship using its neo_id.

   # File lib/neo4j/active_rel/query.rb
17 def find_by_id(key, session = nil)
18   options = session ? {session: session} : {}
19   query ||= Neo4j::ActiveBase.new_query(options)
20   result = query.match('()-[r]-()').where('ID(r)' => key.to_i).limit(1).return(:r).first
21   fail RecordNotFound.new("Couldn't find #{name} with 'id'=#{key.inspect}", name, key) if result.blank?
22   result.r
23 end
first() click to toggle source
   # File lib/neo4j/active_rel/query.rb
40 def first
41   all_query.limit(1).order('ID(r1)').pluck(:r1).first
42 end
last() click to toggle source
   # File lib/neo4j/active_rel/query.rb
44 def last
45   all_query.limit(1).order('ID(r1) DESC').pluck(:r1).first
46 end
where(args = {}) click to toggle source

Performs a very basic match on the relationship. This is not executed lazily, it will immediately return matching objects. To use a string, prefix the property with “r1” @example Match with a string

MyRelClass.where('r1.grade > r1')
   # File lib/neo4j/active_rel/query.rb
30 def where(args = {})
31   where_query.where(where_string(args)).pluck(:r1)
32 end

Private Instance Methods

all_query() click to toggle source
   # File lib/neo4j/active_rel/query.rb
59 def all_query
60   deprecation_warning!
61   Neo4j::ActiveBase.new_query.match("#{cypher_string}-[r1:`#{self._type}`]->#{cypher_string(:inbound)}")
62 end
as_constant(given_class) click to toggle source
   # File lib/neo4j/active_rel/query.rb
80 def as_constant(given_class)
81   case given_class
82   when String, Symbol
83     given_class.to_s.constantize
84   when Array
85     fail "ActiveRel query methods are being deprecated and do not support Array (from|to)_class options. Current value: #{given_class}"
86   else
87     given_class
88   end
89 end
cypher_label(dir = :outbound) click to toggle source
   # File lib/neo4j/active_rel/query.rb
75 def cypher_label(dir = :outbound)
76   target_class = dir == :outbound ? as_constant(_from_class) : as_constant(_to_class)
77   ":`#{target_class.mapped_label_name}`)"
78 end
cypher_string(dir = :outbound) click to toggle source
   # File lib/neo4j/active_rel/query.rb
64 def cypher_string(dir = :outbound)
65   case dir
66   when :outbound
67     identifier = '(n1'
68     identifier + (_from_class == :any ? ')' : cypher_label(:outbound))
69   when :inbound
70     identifier = '(n2'
71     identifier + (_to_class == :any ? ')' : cypher_label(:inbound))
72   end
73 end
deprecation_warning!() click to toggle source
   # File lib/neo4j/active_rel/query.rb
50 def deprecation_warning!
51   ActiveSupport::Deprecation.warn 'The Neo4j::ActiveRel::Query module has been deprecated and will be removed in a future version of the gem.', caller
52 end
where_query() click to toggle source
   # File lib/neo4j/active_rel/query.rb
54 def where_query
55   deprecation_warning!
56   Neo4j::ActiveBase.new_query.match("#{cypher_string(:outbound)}-[r1:`#{self._type}`]->#{cypher_string(:inbound)}")
57 end
where_string(args) click to toggle source
   # File lib/neo4j/active_rel/query.rb
91 def where_string(args)
92   case args
93   when Hash
94     args.map { |k, v| v.is_a?(Integer) ? "r1.#{k} = #{v}" : "r1.#{k} = '#{v}'" }.join(', ')
95   else
96     args
97   end
98 end