Class SelectWithPivotLoader
Implements the logic for loading an association using a SELECT query and a pivot table
Property Summary
- 
        $alias protectedstringThe alias of the association loading the results 
- 
        $associationType protectedstringThe type of the association triggering the load 
- 
        $bindingKey protectedstringThe binding key for the source association. 
- 
        $finder protectedcallableA callable that will return a query object used for loading the association results 
- 
        $foreignKey protectedstring|arrayThe foreignKey to the target association 
- 
        $junctionAssoc protectedCake\ORM\Association\HasManyThe junction association instance 
- 
        $junctionAssociationName protectedstringThe name of the junction association 
- 
        $junctionConditions protectedstring|array|Cake\Database\ExpressionInterface|Closure|nullCustom conditions for the junction association 
- 
        $junctionProperty protectedstringThe property name for the junction association, where its results should be nested at. 
- 
        $sort protectedstringThe sorting options for loading the association 
- 
        $sourceAlias protectedstringThe alias of the source association 
- 
        $strategy protectedstringThe strategy to use for loading, either select or subquery 
- 
        $targetAlias protectedstringThe alias of the target association 
Method Summary
- 
          __construct() publicCopies the options array to properties in this class. The keys in the array correspond to properties in this class. 
- 
          _addFilteringCondition() protectedAppends any conditions required to load the relevant set of records in the target table query given a filter key and some filtering values. 
- 
          _addFilteringJoin() protectedAppends any conditions required to load the relevant set of records in the target table query given a filter key and some filtering values when the filtering needs to be done using a subquery. 
- 
          _assertFieldsPresent() protectedChecks that the fetching query either has auto fields on or has the foreignKey fields selected. If the required fields are missing, throws an exception. 
- 
          _buildQuery() protectedAuxiliary function to construct a new Query object to return all the records in the target table that are associated to those specified in $options from the source table. 
- 
          _buildResultMap() protectedBuilds an array containing the results from fetchQuery indexed by the foreignKey value corresponding to this association. 
- 
          _buildSubquery() protectedBuilds a query to be used as a condition for filtering records in the target table, it is constructed by cloning the original query that was used to load records in the source table. 
- 
          _createTupleCondition() protectedReturns a TupleComparison object that can be used for matching all the fields from $keys with the tuple values in $filter using the provided operator. 
- 
          _defaultOptions() protectedReturns the default options to use for the eagerLoader 
- 
          _extractFinder() protectedHelper method to infer the requested finder and its options. 
- 
          _linkField() protectedGenerates a string used as a table field that contains the values upon which the filter should be applied 
- 
          _multiKeysInjector() protectedReturns a callable to be used for each row in a query result set for injecting the eager loaded rows when the matching needs to be done with multiple foreign keys 
- 
          _resultInjector() protectedReturns a callable to be used for each row in a query result set for injecting the eager loaded rows 
- 
          _subqueryFields() protectedCalculate the fields that need to participate in a subquery. 
- 
          buildEagerLoader() publicReturns a callable that can be used for injecting association results into a given iterator. The options accepted by this method are the same as Association::eagerLoader()
Method Detail
__construct() ¶ public
__construct(array $options)Copies the options array to properties in this class. The keys in the array correspond to properties in this class.
Parameters
- 
                array$options
_addFilteringCondition() ¶ protected
_addFilteringCondition(Cake\ORM\Query $query, string|array $key, mixed $filter): Cake\ORM\QueryAppends any conditions required to load the relevant set of records in the target table query given a filter key and some filtering values.
Parameters
- 
                Cake\ORM\Query$query
- Target table's query 
- 
                string|array$key
- The fields that should be used for filtering 
- 
                mixed$filter
- The value that should be used to match for $key 
Returns
Cake\ORM\Query_addFilteringJoin() ¶ protected
_addFilteringJoin(Cake\ORM\Query $query, string|string[] $key, Cake\ORM\Query $subquery): Cake\ORM\QueryAppends any conditions required to load the relevant set of records in the target table query given a filter key and some filtering values when the filtering needs to be done using a subquery.
Parameters
- 
                Cake\ORM\Query$query
- Target table's query 
- 
                string|string[]$key
- the fields that should be used for filtering 
- 
                Cake\ORM\Query$subquery
- The Subquery to use for filtering 
Returns
Cake\ORM\Query_assertFieldsPresent() ¶ protected
_assertFieldsPresent(Cake\ORM\Query $fetchQuery, array $key): voidChecks that the fetching query either has auto fields on or has the foreignKey fields selected. If the required fields are missing, throws an exception.
Parameters
- 
                Cake\ORM\Query$fetchQuery
- 
                array$key
Returns
void_buildQuery() ¶ protected
_buildQuery(array $options): Cake\ORM\QueryAuxiliary function to construct a new Query object to return all the records in the target table that are associated to those specified in $options from the source table.
This is used for eager loading records on the target table based on conditions.
Parameters
- 
                array$options
- options accepted by eagerLoader() 
Returns
Cake\ORM\QueryThrows
InvalidArgumentExceptionWhen a key is required for associations but not selected.
_buildResultMap() ¶ protected
_buildResultMap(Cake\ORM\Query $fetchQuery, array $options): arrayBuilds an array containing the results from fetchQuery indexed by the foreignKey value corresponding to this association.
Parameters
- 
                Cake\ORM\Query$fetchQuery
- The query to get results from 
- 
                array$options
- The options passed to the eager loader 
Returns
arrayThrows
RuntimeExceptionwhen the association property is not part of the results set.
_buildSubquery() ¶ protected
_buildSubquery(Cake\ORM\Query $query): Cake\ORM\QueryBuilds a query to be used as a condition for filtering records in the target table, it is constructed by cloning the original query that was used to load records in the source table.
Parameters
- 
                Cake\ORM\Query$query
- the original query used to load source records 
Returns
Cake\ORM\Query_createTupleCondition() ¶ protected
_createTupleCondition(Cake\ORM\Query $query, string[] $keys, mixed $filter, string $operator): Cake\Database\Expression\TupleComparisonReturns a TupleComparison object that can be used for matching all the fields from $keys with the tuple values in $filter using the provided operator.
Parameters
- 
                Cake\ORM\Query$query
- Target table's query 
- 
                string[]$keys
- the fields that should be used for filtering 
- 
                mixed$filter
- the value that should be used to match for $key 
- 
                string$operator
- The operator for comparing the tuples 
Returns
Cake\Database\Expression\TupleComparison_defaultOptions() ¶ protected
_defaultOptions(): arrayReturns the default options to use for the eagerLoader
Returns
array_extractFinder() ¶ protected
_extractFinder(string|array $finderData): arrayHelper method to infer the requested finder and its options.
Returns the inferred options from the finder $type.
Examples:
The following will call the finder 'translations' with the value of the finder as its options: $query->contain(['Comments' => ['finder' => ['translations']]]); $query->contain(['Comments' => ['finder' => ['translations' => []]]]); $query->contain(['Comments' => ['finder' => ['translations' => ['locales' => ['en_US']]]]]);
Parameters
- 
                string|array$finderData
- The finder name or an array having the name as key and options as value. 
Returns
array_linkField() ¶ protected
_linkField(array $options): string|string[]Generates a string used as a table field that contains the values upon which the filter should be applied
Parameters
- 
                array$options
- the options to use for getting the link field. 
Returns
string|string[]_multiKeysInjector() ¶ protected
_multiKeysInjector(array $resultMap, string[] $sourceKeys, string $nestKey): ClosureReturns a callable to be used for each row in a query result set for injecting the eager loaded rows when the matching needs to be done with multiple foreign keys
Parameters
- 
                array$resultMap
- A keyed arrays containing the target table 
- 
                string[]$sourceKeys
- An array with aliased keys to match 
- 
                string$nestKey
- The key under which results should be nested 
Returns
Closure_resultInjector() ¶ protected
_resultInjector(Cake\ORM\Query $fetchQuery, array $resultMap, array $options): ClosureReturns a callable to be used for each row in a query result set for injecting the eager loaded rows
Parameters
- 
                Cake\ORM\Query$fetchQuery
- the Query used to fetch results 
- 
                array$resultMap
- an array with the foreignKey as keys and the corresponding target table results as value. 
- 
                array$options
- The options passed to the eagerLoader method 
Returns
Closure_subqueryFields() ¶ protected
_subqueryFields(Cake\ORM\Query $query): arrayCalculate the fields that need to participate in a subquery.
Normally this includes the binding key columns. If there is a an ORDER BY, those columns are also included as the fields may be calculated or constant values, that need to be present to ensure the correct association data is loaded.
Parameters
- 
                Cake\ORM\Query$query
- The query to get fields from. 
Returns
arrayThe list of fields for the subquery.
buildEagerLoader() ¶ public
buildEagerLoader(array $options): ClosureReturns a callable that can be used for injecting association results into a given
iterator. The options accepted by this method are the same as Association::eagerLoader()
Parameters
- 
                array$options
- Same options as - Association::eagerLoader()
Returns
ClosureProperty Detail
$finder ¶ protected
A callable that will return a query object used for loading the association results
Type
callable$junctionConditions ¶ protected
Custom conditions for the junction association
Type
string|array|Cake\Database\ExpressionInterface|Closure|null$junctionProperty ¶ protected
The property name for the junction association, where its results should be nested at.
Type
string