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.



36
37
38
# File 'lib/neo4j/active_rel/query.rb', line 36

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



11
12
13
14
# File 'lib/neo4j/active_rel/query.rb', line 11

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 = nil) ⇒ Object

Loads the relationship using its neo_id.



17
18
19
20
21
22
23
# File 'lib/neo4j/active_rel/query.rb', line 17

def find_by_id(key, session = nil)
  options = session ? {session: session} : {}
  query ||= Neo4j::ActiveBase.new_query(options)
  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



40
41
42
# File 'lib/neo4j/active_rel/query.rb', line 40

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

#lastObject



44
45
46
# File 'lib/neo4j/active_rel/query.rb', line 44

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


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

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