CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.4 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.4
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
      • Association
        • Loader
      • Behavior
      • Exception
      • Locator
      • Rule
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class SelectLoader

Implements the logic for loading an association using a SELECT query

Namespace: Cake\ORM\Association\Loader

Property Summary

  • $alias protected
    string

    The alias of the association loading the results

  • $associationType protected
    string

    The type of the association triggering the load

  • $bindingKey protected
    string

    The binding key for the source association.

  • $finder protected
    callable

    A callable that will return a query object used for loading the association results

  • $foreignKey protected
    array|string

    The foreignKey to the target association

  • $sort protected
    string

    The sorting options for loading the association

  • $sourceAlias protected
    string

    The alias of the source association

  • $strategy protected
    string

    The strategy to use for loading, either select or subquery

  • $targetAlias protected
    string

    The alias of the target association

Method Summary

  • __construct() public

    Copies the options array to properties in this class. The keys in the array correspond to properties in this class.

  • _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() 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 when the filtering needs to be done using a subquery.

  • _assertFieldsPresent() protected

    Checks 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() 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() 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

  • _extractFinder() protected

    Helper method to infer the requested finder and its options.

  • _linkField() 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

  • _subqueryFields() protected

    Calculate the fields that need to participate in a subquery.

  • buildEagerLoader() public

    Returns 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<string, mixed> $options)

Copies the options array to properties in this class. The keys in the array correspond to properties in this class.

Parameters
array<string, mixed> $options

Properties to be copied to this class

_addFilteringCondition() ¶ protected

_addFilteringCondition(Cake\ORM\Query $query, array<string>|string $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

array<string>|string $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, array<string>|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

array<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<string> $key): void

Checks 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

The association fetching query

array<string> $key

The foreign key fields to check

Returns
void
Throws
InvalidArgumentException

_buildQuery() ¶ protected

_buildQuery(array<string, mixed> $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<string, mixed> $options

options accepted by eagerLoader()

Returns
Cake\ORM\Query
Throws
InvalidArgumentException
When a key is required for associations but not selected.

_buildResultMap() ¶ protected

_buildResultMap(Cake\ORM\Query $fetchQuery, array<string, mixed> $options): array<string, mixed>

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<string, mixed> $options

The options passed to the eager loader

Returns
array<string, mixed>

_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<string> $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<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(): array<string, mixed>

Returns the default options to use for the eagerLoader

Returns
array<string, mixed>

_extractFinder() ¶ protected

_extractFinder(array|string $finderData): array

Helper 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
array|string $finderData

The finder name or an array having the name as key and options as value.

Returns
array

_linkField() ¶ protected

_linkField(array<string, mixed> $options): array<string>|string

Generates a string used as a table field that contains the values upon which the filter should be applied

Parameters
array<string, mixed> $options

The options for getting the link field.

Returns
array<string>|string
Throws
RuntimeException

_multiKeysInjector() ¶ protected

_multiKeysInjector(array<string, mixed> $resultMap, array<string> $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<string, mixed> $resultMap

A keyed arrays containing the target table

array<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<string, mixed> $resultMap, array<string, mixed> $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<string, mixed> $resultMap

an array with the foreignKey as keys and the corresponding target table results as value.

array<string, mixed> $options

The options passed to the eagerLoader method

Returns
Closure

_subqueryFields() ¶ protected

_subqueryFields(Cake\ORM\Query $query): array<string, array>

Calculate 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
array<string, array>

buildEagerLoader() ¶ public

buildEagerLoader(array<string, mixed> $options): Closure

Returns 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<string, mixed> $options

Same options as Association::eagerLoader()

Returns
Closure

Property Detail

$alias ¶ protected

The alias of the association loading the results

Type
string

$associationType ¶ protected

The type of the association triggering the load

Type
string

$bindingKey ¶ protected

The binding key for the source association.

Type
string

$finder ¶ protected

A callable that will return a query object used for loading the association results

Type
callable

$foreignKey ¶ protected

The foreignKey to the target association

Type
array|string

$sort ¶ protected

The sorting options for loading the association

Type
string

$sourceAlias ¶ protected

The alias of the source association

Type
string

$strategy ¶ protected

The strategy to use for loading, either select or subquery

Type
string

$targetAlias ¶ protected

The alias of the target association

Type
string
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs