module ActiveGraph::Relationship::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/active_graph/relationship/query.rb 34 def all 35 all_query.pluck(:r1) 36 end
find(id)
click to toggle source
Returns the object with the specified neo4j id. @param [String,Integer] id of node to find
# File lib/active_graph/relationship/query.rb 10 def find(id) 11 fail "Unknown argument #{id.class} in find method (expected String or Integer)" if !(id.is_a?(String) || id.is_a?(Integer)) 12 find_by_id(id) 13 end
find_by_id(key)
click to toggle source
Loads the relationship using its neo_id.
# File lib/active_graph/relationship/query.rb 16 def find_by_id(key) 17 query = ActiveGraph::Base.new_query 18 result = query.match('()-[r]-()').where('ID(r)' => key.to_i).limit(1).return(:r).first 19 fail RecordNotFound.new("Couldn't find #{name} with 'id'=#{key.inspect}", name, key) if result.blank? 20 result[:r] 21 end
first()
click to toggle source
# File lib/active_graph/relationship/query.rb 38 def first 39 all_query.limit(1).order('ID(r1)').pluck(:r1).first 40 end
last()
click to toggle source
# File lib/active_graph/relationship/query.rb 42 def last 43 all_query.limit(1).order('ID(r1) DESC').pluck(:r1).first 44 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/active_graph/relationship/query.rb 28 def where(args = {}) 29 where_query.where(where_string(args)).pluck(:r1) 30 end
Private Instance Methods
all_query()
click to toggle source
# File lib/active_graph/relationship/query.rb 57 def all_query 58 deprecation_warning! 59 ActiveGraph::Base.new_query.match("#{cypher_string}-[r1:`#{type}`]->#{cypher_string(:inbound)}") 60 end
as_constant(given_class)
click to toggle source
# File lib/active_graph/relationship/query.rb 78 def as_constant(given_class) 79 case given_class 80 when String, Symbol 81 given_class.to_s.constantize 82 when Array 83 fail "Relationship query methods are being deprecated and do not support Array (from|to)_class options. Current value: #{given_class}" 84 else 85 given_class 86 end 87 end
cypher_label(dir = :outbound)
click to toggle source
# File lib/active_graph/relationship/query.rb 73 def cypher_label(dir = :outbound) 74 target_class = dir == :outbound ? as_constant(_from_class) : as_constant(_to_class) 75 ":`#{target_class.mapped_label_name}`)" 76 end
cypher_string(dir = :outbound)
click to toggle source
# File lib/active_graph/relationship/query.rb 62 def cypher_string(dir = :outbound) 63 case dir 64 when :outbound 65 identifier = '(n1' 66 identifier + (_from_class == :any ? ')' : cypher_label(:outbound)) 67 when :inbound 68 identifier = '(n2' 69 identifier + (_to_class == :any ? ')' : cypher_label(:inbound)) 70 end 71 end
deprecation_warning!()
click to toggle source
# File lib/active_graph/relationship/query.rb 48 def deprecation_warning! 49 ActiveSupport::Deprecation.warn 'The ActiveGraph::Relationship::Query module has been deprecated and will be removed in a future version of the gem.', caller 50 end
where_query()
click to toggle source
# File lib/active_graph/relationship/query.rb 52 def where_query 53 deprecation_warning! 54 ActiveGraph::Base.new_query.match("#{cypher_string(:outbound)}-[r1:`#{type}`]->#{cypher_string(:inbound)}") 55 end
where_string(args)
click to toggle source
# File lib/active_graph/relationship/query.rb 89 def where_string(args) 90 case args 91 when Hash 92 args.map { |k, v| v.is_a?(Integer) ? "r1.#{k} = #{v}" : "r1.#{k} = '#{v}'" }.join(', ') 93 else 94 args 95 end 96 end