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 30 def all 31 all_query.pluck(:r1) 32 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 9 def find(id, session = self.neo4j_session) 10 fail "Unknown argument #{id.class} in find method (expected String or Integer)" if !(id.is_a?(String) || id.is_a?(Integer)) 11 find_by_id(id, session) 12 end
find_by_id(key, session = Neo4j::Session.current!)
click to toggle source
Loads the relationship using its neo_id.
# File lib/neo4j/active_rel/query.rb 15 def find_by_id(key, session = Neo4j::Session.current!) 16 session.query.match('()-[r]-()').where('ID(r)' => key.to_i).limit(1).return(:r).first.r 17 end
first()
click to toggle source
# File lib/neo4j/active_rel/query.rb 34 def first 35 all_query.limit(1).order('ID(r1)').pluck(:r1).first 36 end
last()
click to toggle source
# File lib/neo4j/active_rel/query.rb 38 def last 39 all_query.limit(1).order('ID(r1) DESC').pluck(:r1).first 40 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 24 def where(args = {}) 25 where_query.where(where_string(args)).pluck(:r1) 26 end
Private Instance Methods
all_query()
click to toggle source
# File lib/neo4j/active_rel/query.rb 53 def all_query 54 deprecation_warning! 55 Neo4j::Session.query.match("#{cypher_string}-[r1:`#{self._type}`]->#{cypher_string(:inbound)}") 56 end
as_constant(given_class)
click to toggle source
# File lib/neo4j/active_rel/query.rb 74 def as_constant(given_class) 75 case given_class 76 when String, Symbol 77 given_class.to_s.constantize 78 when Array 79 fail "ActiveRel query methods are being deprecated and do not support Array (from|to)_class options. Current value: #{given_class}" 80 else 81 given_class 82 end 83 end
cypher_label(dir = :outbound)
click to toggle source
# File lib/neo4j/active_rel/query.rb 69 def cypher_label(dir = :outbound) 70 target_class = dir == :outbound ? as_constant(_from_class) : as_constant(_to_class) 71 ":`#{target_class.mapped_label_name}`)" 72 end
cypher_string(dir = :outbound)
click to toggle source
# File lib/neo4j/active_rel/query.rb 58 def cypher_string(dir = :outbound) 59 case dir 60 when :outbound 61 identifier = '(n1' 62 identifier + (_from_class == :any ? ')' : cypher_label(:outbound)) 63 when :inbound 64 identifier = '(n2' 65 identifier + (_to_class == :any ? ')' : cypher_label(:inbound)) 66 end 67 end
deprecation_warning!()
click to toggle source
# File lib/neo4j/active_rel/query.rb 44 def deprecation_warning! 45 ActiveSupport::Deprecation.warn 'The Neo4j::ActiveRel::Query module has been deprecated and will be removed in a future version of the gem.', caller 46 end
where_query()
click to toggle source
# File lib/neo4j/active_rel/query.rb 48 def where_query 49 deprecation_warning! 50 Neo4j::Session.query.match("#{cypher_string(:outbound)}-[r1:`#{self._type}`]->#{cypher_string(:inbound)}") 51 end
where_string(args)
click to toggle source
# File lib/neo4j/active_rel/query.rb 85 def where_string(args) 86 case args 87 when Hash 88 args.map { |k, v| v.is_a?(Integer) ? "r1.#{k} = #{v}" : "r1.#{k} = '#{v}'" }.join(', ') 89 else 90 args 91 end 92 end