Trait SelectableAssociationTrait
Represents a type of association that that can be fetched using another query
Method Summary
-
_addFilteringCondition() protected
Appends any conditions required to load the relevant set of records in the target table query given a filter key and some filtering values.
-
_addFilteringJoin() public
Appends 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.
-
_buildQuery() protected
Auxiliary 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() abstract protected
Builds an array containing the results from fetchQuery indexed by the foreignKey value corresponding to this association.
-
_buildSubquery() protected
Builds 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() protected
Returns 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() protected
Returns the default options to use for the eagerLoader
-
_linkField() abstract protected
Generates a string used as a table field that contains the values upon which the filter should be applied
-
_multiKeysInjector() protected
Returns 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() protected
Returns a callable to be used for each row in a query result set for injecting the eager loaded rows
-
eagerLoader() public
{@inheritDoc}
-
requiresKeys() public
Returns true if the eager loading process will require a set of the owning table's binding keys in order to use them as a filter in the finder query.
Method Detail
_addFilteringCondition() ¶ protected
_addFilteringCondition(Cake\ORM\Query $query, string|array $key, mixed $filter): Cake\ORM\Query
Appends 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() ¶ public
_addFilteringJoin(Cake\ORM\Query $query, string $key, Cake\ORM\Query $subquery): Cake\ORM\Query
Appends 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
$key the fields that should be used for filtering
-
Cake\ORM\Query
$subquery The Subquery to use for filtering
Returns
Cake\ORM\Query
_buildQuery() ¶ protected
_buildQuery(array $options): Cake\ORM\Query
Auxiliary 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
Parameters
-
array
$options options accepted by eagerLoader()
Returns
Cake\ORM\Query
Throws
InvalidArgumentException
When a key is required for associations but not selected.
_buildResultMap() ¶ abstract protected
_buildResultMap(Cake\ORM\Query $fetchQuery, array $options): array
Builds 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
array
_buildSubquery() ¶ protected
_buildSubquery(Cake\ORM\Query $query): Cake\ORM\Query
Builds 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, array $keys, mixed $filter, string $operator): Cake\Database\Expression\TupleComparison
Returns 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
-
array
$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(): array
Returns the default options to use for the eagerLoader
Returns
array
_linkField() ¶ abstract protected
_linkField(array $options): string|array
Generates a string used as a table field that contains the values upon which the filter should be applied
Parameters
-
array
$options The options for getting the link field.
Returns
string|array
_multiKeysInjector() ¶ protected
_multiKeysInjector(array $resultMap, array $sourceKeys, string $nestKey): Closure
Returns 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
-
array
$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): Closure
Returns 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
requiresKeys() ¶ public
requiresKeys(array $options = []): bool
Returns true if the eager loading process will require a set of the owning table's binding keys in order to use them as a filter in the finder query.
Parameters
-
array
$options optional The options containing the strategy to be used.
Returns
bool