Module: ActiveGraph::Relationship::Query::ClassMethods
- Defined in:
- lib/active_graph/relationship/query.rb
Instance Method Summary collapse
-
#all ⇒ Object
Performs a basic match on the relationship, returning all results.
-
#find(id) ⇒ Object
Returns the object with the specified neo4j id.
- #find_by(args) ⇒ Object
-
#find_by_id(key) ⇒ Object
Loads the relationship using its neo_id.
- #first ⇒ Object
- #last ⇒ Object
-
#where(args = {}) ⇒ Object
Performs a very basic match on the relationship.
Instance Method Details
#all ⇒ Object
Performs a basic match on the relationship, returning all results. This is not executed lazily, it will immediately return matching objects.
37 38 39 |
# File 'lib/active_graph/relationship/query.rb', line 37 def all all_query.pluck(:r1) end |
#find(id) ⇒ Object
Returns the object with the specified neo4j id.
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)" unless [Integer, String].any?(&id.method(:is_a?)) find_by_id(id) || fail(RecordNotFound.new("Couldn't find #{name} with 'id'=#{id.inspect}", name, id)) end |
#find_by(args) ⇒ Object
31 32 33 |
# File 'lib/active_graph/relationship/query.rb', line 31 def find_by(args) where(args).first end |
#find_by_id(key) ⇒ Object
Loads the relationship using its neo_id.
16 17 18 19 20 |
# File 'lib/active_graph/relationship/query.rb', line 16 def find_by_id(key) query = ActiveGraph::Base.new_query result = query.match("()-[r:`#{mapped_element_name}`]-()").where("r.#{id_property_name}" => key).limit(1).return(:r).first result&.send(:[], :r) end |
#first ⇒ Object
41 42 43 |
# File 'lib/active_graph/relationship/query.rb', line 41 def first all_query.limit(1).order('r1.created_at').pluck(:r1).first end |
#last ⇒ Object
45 46 47 |
# File 'lib/active_graph/relationship/query.rb', line 45 def last all_query.limit(1).order('r1.created_at 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”
27 28 29 |
# File 'lib/active_graph/relationship/query.rb', line 27 def where(args = {}) where_query.where(where_string(args)).pluck(:r1) end |