protected function _assertFieldsPresent($fetchQuery, $key)
    {
        $select = $fetchQuery->aliasFields($fetchQuery->clause('select'));
        if (empty($select)) {
            return;
        }
        $missingKey = function ($fieldList, $key) {
            foreach ($key as $keyField) {
                if (!in_array($keyField, $fieldList, true)) {
                    return true;
                }
            }

            return false;
        };

        $missingFields = $missingKey($select, $key);
        if ($missingFields) {
            $driver = $fetchQuery->getConnection()->getDriver();
            $quoted = array_map([$driver, 'quoteIdentifier'], $key);
            $missingFields = $missingKey($select, $quoted);
        }

        if ($missingFields) {
            throw new InvalidArgumentException(
                sprintf(
                    'You are required to select the "%s" field(s)',
                    implode(', ', (array)$key)
                )
            );
        }
    }
protected function _assertFieldsPresent($fetchQuery, $key)
    {
        $select = $fetchQuery->aliasFields($fetchQuery->clause('select'));
        if (empty($select)) {
            return;
        }
        $missingKey = function ($fieldList, $key) {
            foreach ($key as $keyField) {
                if (!in_array($keyField, $fieldList, true)) {
                    return true;
                }
            }

            return false;
        };

        $missingFields = $missingKey($select, $key);
        if ($missingFields) {
            $driver = $fetchQuery->getConnection()->getDriver();
            $quoted = array_map([$driver, 'quoteIdentifier'], $key);
            $missingFields = $missingKey($select, $quoted);
        }

        if ($missingFields) {
            throw new InvalidArgumentException(
                sprintf(
                    'You are required to select the "%s" field(s)',
                    implode(', ', (array)$key)
                )
            );
        }
    }
protected function _assertFieldsPresent ( $ fetchQuery , $ key ) { $ select = $ fetchQuery -> aliasFields ( $ fetchQuery -> clause ( 'select' ) ) ; if ( empty ( $ select ) ) { return ; } $ missingKey = function ( $ fieldList , $ key ) { foreach ( $ key as $ keyField ) { if ( ! in_array ( $ keyField , $ fieldList , true ) ) { return true ; } } return false ; } ; $ missingFields = $ missingKey ( $ select , $ key ) ; if ( $ missingFields ) { $ driver = $ fetchQuery -> getConnection ( ) -> getDriver ( ) ; $ quoted = array_map ( [ $ driver , 'quoteIdentifier' ] , $ key ) ; $ missingFields = $ missingKey ( $ select , $ quoted ) ; } if ( $ missingFields ) { throw new InvalidArgumentException ( sprintf ( 'You are required to select the "%s" field(s)' , implode ( ', ' , ( array ) $ key ) ) ) ; } }
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.

@param \Cake\ORM\Query $fetchQuery The association fetching query
@param array $key The foreign key fields to check
@return void
@throws \InvalidArgumentException
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 .