motion/cdq/targeted_query.rb in cdq-1.0.3 vs motion/cdq/targeted_query.rb in cdq-1.0.4
- old
+ new
@@ -70,10 +70,11 @@
# Return the last entity matching the query.
#
# Causes execution.
#
def last(n = 1)
+ return nil if count == 0
result = offset(count - n).limit(n).array
n == 1 ? result.first : result
end
# Fetch a single entity from the query by index. If the optional
@@ -118,32 +119,32 @@
r = context.executeFetchRequest(fr, error:error)
r.first[desc_name]
end
end
- # Calculates the sum of values on a given column.
+ # Calculates the sum of values on a given column.
#
# Author.sum(:fee) # => 6.0
def sum(column_name)
calculate(:sum, column_name)
end
-
- # Calculates the average of values on a given column.
+
+ # Calculates the average of values on a given column.
#
# Author.average(:fee) # => 2.0
def average(column_name)
calculate(:average, column_name)
end
- # Calculates the minimum of values on a given column.
+ # Calculates the minimum of values on a given column.
#
# Author.min(:fee) # => 1.0
def min(column_name)
calculate(:min, column_name)
end
alias :minimum :min
- # Calculates the maximum of values on a given column.
+ # Calculates the maximum of values on a given column.
#
# Author.max(:fee) # => 3.0
def max(column_name)
calculate(:max, column_name)
end