Class ResultSet

Represents the results obtained after executing a query for a specific table This object is responsible for correctly nesting result keys reported from the query, casting each field to the correct type and executing the extra queries required for eager loading external associations.

Cake\ORM\ResultSet implements Cake\Datasource\ResultSetInterface uses Cake\Collection\CollectionTrait
Namespace: Cake\ORM
Location: ORM/ResultSet.php

Properties summary

  • $_autoFields protected
    boolean
    Tracks value of $_autoFields property of $query passed to constructor.
  • $_containMap protected
    array
    List of associations that should be eager loaded.
  • $_count protected
    integer
    Holds the count of records in this result set
  • $_current protected
    array
    Last record fetched from the statement
  • $_defaultAlias protected
    string
    The default table alias
  • $_defaultTable protected
    Default table instance
  • $_driver protected
    The Database driver object.
  • $_entityClass protected
    string
    The fully namespaced name of the class to use for hydrating results
  • $_hydrate protected
    boolean
    Whether to hydrate results into objects or not
  • $_index protected
    integer
    Points to the next record number that should be fetched
  • $_map protected
    array

    Map of fields that are fetched from the statement with their type and the table they belong to

  • $_matchingMap protected
    array

    List of associations that should be placed under the _matchingData result key.

  • array

    List of matching associations and the column keys to expect from each of them.

  • $_query protected
    Original query from where results were generated
  • $_results protected
    array|ArrayAccess
    Results that have been fetched or hydrated into the results.
  • $_statement protected
    Database statement holding the results
  • $_types protected
    array
    Type cache for type converters.
  • $_useBuffering protected
    boolean
    Whether or not to buffer results fetched from the statement

Method Summary

  • __construct() public
    Constructor
  • __debugInfo() public

    Returns an array that can be used to describe the internal state of this object.

  • Calculates the list of associations that should get eager loaded when fetching each record

  • Creates a map of row keys out of the query select clause that can be used to hydrate nested result sets more quickly.

  • _calculateTypeMap() protected deprecated

    Creates a map of Type converter classes for each of the columns that should be fetched by this object.

  • _castValues() protected deprecated

    Casts all values from a row brought from a table to the correct PHP type.

  • _fetchResult() protected

    Helper function to fetch the next result from the statement or seeded results.

  • _getTypes() protected deprecated

    Returns the Type classes for each of the passed fields belonging to the table.

  • _groupResult() protected
    Correctly nests results keys including those coming from associations
  • count() public
    Gives the number of rows in the result set.
  • current() public
    Returns the current record in the result iterator
  • first() public
    Get the first record from a result set.
  • key() public
    Returns the key of the current record in the iterator
  • next() public
    Advances the iterator pointer to the next record
  • rewind() public
    Rewinds a ResultSet.
  • serialize() public
    Serializes a resultset.
  • unserialize() public
    Unserializes a resultset.
  • valid() public
    Whether there are more results to be fetched from the iterator

Method Detail

__construct()source public

__construct( Cake\ORM\Query $query , Cake\Database\StatementInterface $statement )

Constructor

Parameters

Cake\ORM\Query $query
Query from where results come
Cake\Database\StatementInterface $statement
The statement to fetch from

__debugInfo()source public

__debugInfo( )

Returns an array that can be used to describe the internal state of this object.

Returns

array

_calculateAssociationMap()source protected

_calculateAssociationMap( Cake\ORM\Query $query )

Calculates the list of associations that should get eager loaded when fetching each record

Parameters

Cake\ORM\Query $query
The query from where to derive the associations

_calculateColumnMap()source protected

_calculateColumnMap( Cake\ORM\Query $query )

Creates a map of row keys out of the query select clause that can be used to hydrate nested result sets more quickly.

Parameters

Cake\ORM\Query $query
The query from where to derive the column map

_calculateTypeMap()source protected deprecated

_calculateTypeMap( )

Creates a map of Type converter classes for each of the columns that should be fetched by this object.

Deprecated

3.2.0 Not used anymore. Type casting is done at the statement level

_castValues()source protected deprecated

_castValues( string $alias , array $values )

Casts all values from a row brought from a table to the correct PHP type.

Deprecated

3.2.0 Not used anymore. Type casting is done at the statement level

Parameters

string $alias
The table object alias
array $values
The values to cast

Returns

array

_fetchResult()source protected

_fetchResult( )

Helper function to fetch the next result from the statement or seeded results.

Returns

mixed

_getTypes()source protected deprecated

_getTypes( Cake\ORM\Table $table , array $fields )

Returns the Type classes for each of the passed fields belonging to the table.

Deprecated

3.2.0 Not used anymore. Type casting is done at the statement level

Parameters

Cake\ORM\Table $table
The table from which to get the schema
array $fields
The fields whitelist to use for fields in the schema.

Returns

array

_groupResult()source protected

_groupResult( array $row )

Correctly nests results keys including those coming from associations

Parameters

array $row
Array containing columns and values or false if there is no results

Returns

array
Results

count()source public

count( )

Gives the number of rows in the result set.

Part of the Countable interface.

Returns

integer

Implementation of

Cake\Collection\CollectionInterface::count()

current()source public

current( )

Returns the current record in the result iterator

Part of Iterator interface.

Returns

array|object

Implementation of

Iterator::current()

first()source public

first( )

Get the first record from a result set.

This method will also close the underlying statement cursor.

Returns

array|object

Implementation of

Cake\Collection\CollectionInterface::first()

key()source public

key( )

Returns the key of the current record in the iterator

Part of Iterator interface.

Returns

integer

Implementation of

Iterator::key()

next()source public

next( )

Advances the iterator pointer to the next record

Part of Iterator interface.

Implementation of

Iterator::next()

rewind()source public

rewind( )

Rewinds a ResultSet.

Part of Iterator interface.

Throws

Cake\Database\Exception

Implementation of

Iterator::rewind()

serialize()source public

serialize( )

Serializes a resultset.

Part of Serializable interface.

Returns

string
Serialized object

Implementation of

Serializable::serialize()

unserialize()source public

unserialize( string $serialized )

Unserializes a resultset.

Part of Serializable interface.

Parameters

string $serialized
Serialized object

Implementation of

Serializable::unserialize()

valid()source public

valid( )

Whether there are more results to be fetched from the iterator

Part of Iterator interface.

Returns

boolean

Implementation of

Iterator::valid()

Methods used from Cake\Collection\CollectionTrait

_unwrap()source public

_unwrap( )

append()source public

append( $items )

appendItem()source public

appendItem( $item , $key = null )

avg()source public

avg( $matcher = null )

buffered()source public

buffered( )

Returns

Cake\Collection\Iterator\BufferedIterator

cartesianProduct()source public

cartesianProduct( callable $operation = null , callable $filter = null )

Parameters

callable $operation optional null
Operation
callable $filter optional null
Filter

Returns

Cake\Collection\CollectionInterface

Throws

LogicException

chunk()source public

chunk( $chunkSize )

chunkWithKeys()source public

chunkWithKeys( $chunkSize , $preserveKeys = true )

combine()source public

combine( $keyPath , $valuePath , $groupPath = null )

compile()source public

compile( $preserveKeys = true )

contains()source public

contains( $value )

countBy()source public

countBy( $callback )

countKeys()source public

countKeys( )

Returns

integer

each()source public

each( callable $c )

every()source public

every( callable $c )

extract()source public

extract( $matcher )

filter()source public

filter( callable $c = null )

Returns

Cake\Collection\Iterator\FilterIterator

firstMatch()source public

firstMatch( array $conditions )

groupBy()source public

groupBy( $callback )

indexBy()source public

indexBy( $callback )

insert()source public

insert( $path , $values )

Returns

Cake\Collection\Iterator\InsertIterator

isEmpty()source public

isEmpty( )

jsonSerialize()source public

jsonSerialize( )

last()source public

last( )

lazy()source public

lazy( )

listNested()source public

listNested( $dir = 'desc' , $nestingKey = 'children' )

Returns

Cake\Collection\Iterator\TreeIterator

map()source public

map( callable $c )

Returns

Cake\Collection\Iterator\ReplaceIterator

match()source public

match( array $conditions )

max()source public

max( $callback , $type = \SORT_NUMERIC )

median()source public

median( $matcher = null )

min()source public

min( $callback , $type = \SORT_NUMERIC )

nest()source public

nest( $idPath , $parentPath , $nestingKey = 'children' )

newCollection()source protected

newCollection( ... $args )

Returns a new collection.

Allows classes which use this trait to determine their own type of returned collection interface

Parameters

... $args
$args Constructor arguments.

Returns

Cake\Collection\CollectionInterface

optimizeUnwrap()source protected

optimizeUnwrap( )

Unwraps this iterator and returns the simplest traversable that can be used for getting the data out

Returns

Traversable|array

prepend()source public

prepend( $items )

prependItem()source public

prependItem( $item , $key = null )

reduce()source public

reduce( callable $c , $zero = null )

reject()source public

reject( callable $c )

Returns

Cake\Collection\Iterator\FilterIterator

sample()source public

sample( $size = 10 )

shuffle()source public

shuffle( )

skip()source public

skip( $howMany )

some()source public

some( callable $c )

sortBy()source public

sortBy( $callback , $dir = \SORT_DESC , $type = \SORT_NUMERIC )

stopWhen()source public

stopWhen( $condition )

Returns

Cake\Collection\Iterator\StoppableIterator

sumOf()source public

sumOf( $matcher = null )

take()source public

take( $size = 1 , $from = 0 )

takeLast()source public

takeLast( $howMany )

through()source public

through( callable $handler )

toArray()source public

toArray( $preserveKeys = true )

toList()source public

toList( )

transpose()source public

transpose( )

Returns

Cake\Collection\CollectionInterface

Throws

LogicException

unfold()source public

unfold( callable $transformer = null )

unwrap()source public

unwrap( )

zip()source public

zip( $items )

zipWith()source public

zipWith( $items , $callable )

Magic methods inherited from Cake\Collection\CollectionInterface

cartesianProduct()

Properties detail

$_autoFieldssource

protected boolean

Tracks value of $_autoFields property of $query passed to constructor.

$_containMapsource

protected array

List of associations that should be eager loaded.

[]

$_countsource

protected integer

Holds the count of records in this result set

$_currentsource

protected array

Last record fetched from the statement

$_defaultAliassource

protected string

The default table alias

$_defaultTablesource

protected Cake\ORM\Table|Cake\Datasource\RepositoryInterface

Default table instance

$_driversource

protected Cake\Database\Driver

The Database driver object.

Cached in a property to avoid multiple calls to the same function.

$_entityClasssource

protected string

The fully namespaced name of the class to use for hydrating results

$_hydratesource

protected boolean

Whether to hydrate results into objects or not

true

$_indexsource

protected integer

Points to the next record number that should be fetched

$_mapsource

protected array

Map of fields that are fetched from the statement with their type and the table they belong to

[]

$_matchingMapsource

protected array

List of associations that should be placed under the _matchingData result key.

[]

$_matchingMapColumnssource

protected array

List of matching associations and the column keys to expect from each of them.

[]

$_querysource

protected Cake\ORM\Query

Original query from where results were generated

Deprecated

3.1.6 Due to a memory leak, this property cannot be used anymore

$_resultssource

protected array|ArrayAccess

Results that have been fetched or hydrated into the results.

[]

$_statementsource

protected Cake\Database\StatementInterface

Database statement holding the results

$_typessource

protected array

Type cache for type converters.

Converters are indexed by alias and column name.

Deprecated

3.2.0 Not used anymore. Type casting is done at the statement level
[]

$_useBufferingsource

protected boolean

Whether or not to buffer results fetched from the statement

true

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.8/class-Cake.ORM.ResultSet.html