Module: ActiveGraph::Relationship::Query::ClassMethods

Defined in:
lib/active_graph/relationship/query.rb

Instance Method Summary collapse

Instance Method Details

#allObject

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



34
35
36
# File 'lib/active_graph/relationship/query.rb', line 34

def all
  all_query.pluck(:r1)
end

#find(id) ⇒ Object

Returns the object with the specified neo4j id.

Parameters:

  • id (String, Integer)

    of node to find



10
11
12
13
# File 'lib/active_graph/relationship/query.rb', line 10

def find(id)
  fail "Unknown argument #{id.class} in find method (expected String or Integer)" if !(id.is_a?(String) || id.is_a?(Integer))
  find_by_id(id)
end

#find_by_id(key) ⇒ Object

Loads the relationship using its neo_id.



16
17
18
19
20
21
# File 'lib/active_graph/relationship/query.rb', line 16

def find_by_id(key)
  query = ActiveGraph::Base.new_query
  result = query.match('()-[r]-()').where('ID(r)' => key.to_i).limit(1).return(:r).first
  fail RecordNotFound.new("Couldn't find #{name} with 'id'=#{key.inspect}", name, key) if result.blank?
  result[:r]
end

#firstObject



38
39
40
# File 'lib/active_graph/relationship/query.rb', line 38

def first
  all_query.limit(1).order('ID(r1)').pluck(:r1).first
end

#lastObject



42
43
44
# File 'lib/active_graph/relationship/query.rb', line 42

def last
  all_query.limit(1).order('ID(r1) DESC').pluck(:r1).first
end

#where(args = {}) ⇒ Object

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”

Examples:

Match with a string

MyRelClass.where('r1.grade > r1')


28
29
30
# File 'lib/active_graph/relationship/query.rb', line 28

def where(args = {})
  where_query.where(where_string(args)).pluck(:r1)
end