Class: ActiveRecord::Embedded::Aggregation::Postgresql

Inherits:
ActiveRecord::Embedded::Aggregation show all
Defined in:
lib/active_record/embedded/aggregation/postgresql.rb

Overview

Driver for JSON/JSONB query support in PostgreSQL. Uses a @> query to look for partial JSON in the data Array.

Instance Method Summary collapse

Methods inherited from ActiveRecord::Embedded::Aggregation

#each, #initialize

Methods included from Interface

#create, #find, #types

Methods included from Query

#build, #create, #create!, #find, #find!, #find_by, #find_by!, #initialize, #inspect, #limit, #offset, #order, #where

Constructor Details

This class inherits a constructor from ActiveRecord::Embedded::Aggregation

Instance Method Details

#resultsObject



11
12
13
14
15
16
# File 'lib/active_record/embedded/aggregation/postgresql.rb', line 11

def results
  criteria = parent.where("#{as} @> ?", params)
  criteria = criteria.offset(from) unless from.zero?
  criteria = criteria.limit(to) unless to == -1
  criteria.map { |record| [record, query_for(record)] }
end