Skip to content

[4.3.1][ORM] Table::loadinto() fail with The includeFields association is not defined #16362

@Cyrille37

Description

@Cyrille37

Description

Hello

In some case $aTable->loadInto( $this, [ 'bTable.cTable' ] ); failed with error "The includeFields association is not defined on UserGroups. Valid associations are: Parent, SiblingChildren".

Sorry, I've no simple TestCase/UnitTest :(

But if I comment $config['includeFields'] = true; in Cake\ORM\LazyEagerLoader::_getQuery() in attachableAssociations() loop every things work without error.

// vendor/cakephp/cakephp/src/ORM/LazyEagerLoader.php
namespace Cake\ORM;
class LazyEagerLoader
{
    ...
    protected function _getQuery(CollectionInterface $objects, array $contain, Table $source): Query
    {
        ...
        foreach ($query->getEagerLoader()->attachableAssociations($source) as $loadable) {
            $config = $loadable->getConfig();
            // $config['includeFields'] = true; <- COMMENT HERE
            $loadable->setConfig($config);
        }
        return $query;
    }

Effectively if not commented, the EagerLoader::_normalizeContain() try to addAssociation( "includeFields" ) which is a forced configuration not a table :-(

// vendor/cakephp/cakephp/src/ORM/EagerLoader.php
namespace Cake\ORM;
class EagerLoader
{
    ...
    protected function _normalizeContain(Table $parent, string $alias, array $options, array $paths): EagerLoadable
    {
        ...
        foreach ($extra as $t => $assoc) {
            Log::debug(__METHOD__.' $t: '.$t);  // <-- Here $t == "includeFields" ;
            $eagerLoadable->addAssociation( $t, $this->_normalizeContain($table, $t, $assoc, $paths)
            );
        }
        return $eagerLoadable;
    }

CakePHP Version

4.3.1

PHP Version

7.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions