lib/hari/node/queries/relation.rb in hari-0.0.4 vs lib/hari/node/queries/relation.rb in hari-0.0.5

- old
+ new

@@ -26,11 +26,11 @@ def backend options[:backend] end def calculate_limit - options[:limit] || -1 + (options[:limit].presence || -1).to_i end %w(limit step).each do |method| define_method method do |value| options[method.to_sym] = value @@ -64,19 +64,31 @@ fail 'type not supported for chained queries' if level > 1 Type.new self, name end + def first + limit(1).to_a.first + end + def count options[:result_type] = :count result end def start_node level == 1 ? parent.node : parent.start_node end + def <<(nodes) + fail 'cannot create relation for chained queries' if level > 1 + + Array(nodes).each do |node| + Hari.relation! relation, parent.node, Hari(node) + end + end + def call(final = true) if level == 1 backend.fetch parent.node, call_args(final) else backend.step start_node, parent.call(false), call_args(final) @@ -85,9 +97,10 @@ def call_args(final = true) { relation: relation, direction: direction, + position: direction == :in ? 0 : 2, limit: calculate_limit, from: options[:from], step: options[:step], result: result_type(final) }