Module: Neo4j::ActiveRel::Query::ClassMethods

Defined in:
lib/neo4j/active_rel/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.



30
31
32
# File 'lib/neo4j/active_rel/query.rb', line 30

def all
  all_query.pluck(:r1)
end

#find(id, session = self.neo4j_session) ⇒ Object

Returns the object with the specified neo4j id.

Parameters:

  • id (String, Integer)

    of node to find

  • session (Neo4j::Session) (defaults to: self.neo4j_session)

    optional



9
10
11
12
# File 'lib/neo4j/active_rel/query.rb', line 9

def find(id, session = self.neo4j_session)
  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, session)
end

#find_by_id(key, session = Neo4j::Session.current!) ⇒ Object

Loads the relationship using its neo_id.



15
16
17
# File 'lib/neo4j/active_rel/query.rb', line 15

def find_by_id(key, session = Neo4j::Session.current!)
  session.query.match('()-[r]-()').where('ID(r)' => key.to_i).limit(1).return(:r).first.r
end

#firstObject



34
35
36
# File 'lib/neo4j/active_rel/query.rb', line 34

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

#lastObject



38
39
40
# File 'lib/neo4j/active_rel/query.rb', line 38

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')


24
25
26
# File 'lib/neo4j/active_rel/query.rb', line 24

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