Method: Parse::Query#results

Defined in:
lib/parse/query.rb

#results(raw: false) { ... } ⇒ Array<Hash>, Array<Parse::Object> Also known as: result

Executes the query and builds the result set of Parse::Objects that matched. When this method is passed a block, the block is yielded for each matching item in the result, and the items are not returned. This methodology is more performant as large quantifies of objects are fetched in batches and all of them do not have to be kept in memory after the query finishes executing. This is the recommended method of processing large result sets.

Examples:

query = Parse::Query.new("_User", :created_at.before => DateTime.now)
users = query.results # => Array of Parse::User objects.

query = Parse::Query.new("_User", limit: :max)

query.results do |user|
 # recommended; more memory efficient
end

Parameters:

  • raw (Boolean) (defaults to: false)

    whether to get the raw hash results of the query instead of a set of Parse::Object subclasses.

Yields:

  • a block to iterate for each object that matched the query.

Returns:

  • (Array<Hash>)

    if raw is set to true, a set of Parse JSON hashes.

  • (Array<Parse::Object>)

    if raw is set to false, a list of matching Parse::Object subclasses.



799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
# File 'lib/parse/query.rb', line 799

def results(raw: false)
  if @results.nil?
    if block_given?
      max_results(raw: raw, &Proc.new)
    elsif @limit.is_a?(Numeric)
      response = fetch!(compile)
      return [] if response.error?
      items = raw ? response.results : decode(response.results)
      return items.each(&Proc.new) if block_given?
      @results = items
    else
      @results = max_results(raw: raw)
    end
  end
  @results
end