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
Properties summary
-
$_autoFields
protectedTracks value of $_autoFields property of $query passed to constructor.boolean
-
$_containMap
protectedList of associations that should be eager loaded.array
-
$_count
protectedHolds the count of records in this result setinteger
-
$_current
protectedLast record fetched from the statementarray
-
$_defaultAlias
protectedThe default table aliasstring
-
$_defaultTable
protected -
$_driver
protected -
$_entityClass
protectedThe fully namespaced name of the class to use for hydrating resultsstring
-
$_hydrate
protectedWhether to hydrate results into objects or notboolean
-
$_index
protectedPoints to the next record number that should be fetchedinteger
-
$_map
protectedarray
Map of fields that are fetched from the statement with their type and the table they belong to
-
$_matchingMap
protectedarray
List of associations that should be placed under the
_matchingData
result key. -
$_matchingMapColumns
protectedarray
List of matching associations and the column keys to expect from each of them.
-
$_query
protected -
$_results
protectedResults that have been fetched or hydrated into the results.array|ArrayAccess
-
$_statement
protected -
$_types
protectedType cache for type converters.array
-
$_useBuffering
protectedWhether or not to buffer results fetched from the statementboolean
Method Summary
- __construct() publicConstructor
- __debugInfo() public
Returns an array that can be used to describe the internal state of this object.
- _calculateAssociationMap() protected
Calculates the list of associations that should get eager loaded when fetching each record
- _calculateColumnMap() protected
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
Creates a map of Type converter classes for each of the columns that should be fetched by this object.
- _castValues() protected
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
Returns the Type classes for each of the passed fields belonging to the table.
- _groupResult() protectedCorrectly nests results keys including those coming from associations
- count() publicGives the number of rows in the result set.
- current() publicReturns the current record in the result iterator
- first() publicGet the first record from a result set.
- key() publicReturns the key of the current record in the iterator
- next() publicAdvances the iterator pointer to the next record
- rewind() publicRewinds a ResultSet.
- serialize() publicSerializes a resultset.
- unserialize() publicUnserializes a resultset.
- valid() publicWhether 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
_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
_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 levelParameters
- 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
_getTypes( Cake\ORM\Table $table , array $fields )
Returns the Type classes for each of the passed fields belonging to the table.
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( mixed $row )
Correctly nests results keys including those coming from associations
Parameters
- mixed
$row
- Array containing columns and values or false if there is no results
Returns
arrayResults
count()source public
count( )
Gives the number of rows in the result set.
Part of the Countable interface.
Returns
integerImplementation of
Countable::count()
current()source public
current( )
Returns the current record in the result iterator
Part of Iterator interface.
Returns
array|objectImplementation 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|objectImplementation of
Cake\Collection\CollectionInterface::first()
key()source public
key( )
Returns the key of the current record in the iterator
Part of Iterator interface.
Returns
integerImplementation 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
stringSerialized 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
booleanImplementation of
Iterator::valid()
Methods used from Cake\Collection\CollectionTrait
_unwrap()source public
_unwrap( )
append()source public
append( $items )
avg()source public
avg( $matcher null )
cartesianProduct()source public
cartesianProduct( callable $operation null , callable $filter null )
Returns
Cake\Collection\CollectionInterface
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 )
each()source public
each( callable $c )
every()source public
every( callable $c )
extract()source public
extract( $matcher )
firstMatch()source public
firstMatch( array $conditions )
groupBy()source public
groupBy( $callback )
indexBy()source public
indexBy( $callback )
isEmpty()source public
isEmpty( )
jsonSerialize()source public
jsonSerialize( )
last()source public
last( )
listNested()source public
listNested( $dir 'desc' , $nestingKey 'children' )
Returns
Cake\Collection\Iterator\TreeIterator
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' )
optimizeUnwrap()source protected
optimizeUnwrap( )
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Returns
Traversable|arrayreduce()source public
reduce( callable $c , $zero null )
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 )
sumOf()source public
sumOf( $matcher null )
take()source public
take( $size 1 , $from 0 )
through()source public
through( callable $handler )
toArray()source public
toArray( $preserveKeys true )
toList()source public
toList( )
unfold()source public
unfold( callable $transformer null )
unwrap()source public
unwrap( )
zip()source public
zip( $items )
zipWith()source public
zipWith( $items , $callable )
Properties detail
$_autoFieldssource
protected boolean
Tracks value of $_autoFields property of $query passed to constructor.
$_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
$_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.
[]
$_typessource
protected array
Type cache for type converters.
Converters are indexed by alias and column name.
[]
$_useBufferingsource
protected boolean
Whether or not to buffer results fetched from the statement
true
© 2005–2017 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.4/class-Cake.ORM.ResultSet.html