src/Aggregator/AggregateResult.php
private static function join(AggregatorInterface $aggregator, QueryInterface $query) : QueryInterface
    {
        $config = $aggregator->getConfig();

        if (! $config->joinMode()) {
            return $query;
        }

        Assert::isInstanceOf($query, Query::class);
        $association = static::findAssociation($aggregator);

        // limit to record's associated data
        $query->innerJoinWith($association->getName(), function ($q) use ($association, $config) {
            $table = $config->getJoinTable();
            $primaryKey = $table->getPrimaryKey();
            if (! is_string($primaryKey)) {
                Log::error('Failed to apply inner join for aggregated field value: primary key must be a string', [
                    'source_table' => $config->getTable()->getAlias(),
                    'target_table' => $table->getAlias(),
                    'primar_key' => $table->getPrimaryKey(),
                    'association' => $association->getName()
                ]);

                return $q;
            }

            $entity = $config->getEntity();

            return $q->where([
                $association->getTarget()->aliasField($primaryKey) => $entity->get($primaryKey)
            ]);
        });

        return $query;
    }
private static function join(AggregatorInterface $aggregator, QueryInterface $query) : QueryInterface
    {
        $config = $aggregator->getConfig();

        if (! $config->joinMode()) {
            return $query;
        }

        Assert::isInstanceOf($query, Query::class);
        $association = static::findAssociation($aggregator);

        // limit to record's associated data
        $query->innerJoinWith($association->getName(), function ($q) use ($association, $config) {
            $table = $config->getJoinTable();
            $primaryKey = $table->getPrimaryKey();
            if (! is_string($primaryKey)) {
                Log::error('Failed to apply inner join for aggregated field value: primary key must be a string', [
                    'source_table' => $config->getTable()->getAlias(),
                    'target_table' => $table->getAlias(),
                    'primar_key' => $table->getPrimaryKey(),
                    'association' => $association->getName()
                ]);

                return $q;
            }

            $entity = $config->getEntity();

            return $q->where([
                $association->getTarget()->aliasField($primaryKey) => $entity->get($primaryKey)
            ]);
        });

        return $query;
    }
private static function join ( AggregatorInterface $ aggregator , QueryInterface $ query ) : QueryInterface { $ config = $ aggregator -> getConfig ( ) ; if ( ! $ config -> joinMode ( ) ) { return $ query ; } Assert :: isInstanceOf ( $ query , Query :: class ) ; $ association = static :: findAssociation ( $ aggregator ) ; // limit to record's associated data $ query -> innerJoinWith ( $ association -> getName ( ) , function ( $ q ) use ( $ association , $ config ) { $ table = $ config -> getJoinTable ( ) ; $ primaryKey = $ table -> getPrimaryKey ( ) ; if ( ! is_string ( $ primaryKey ) ) { Log :: error ( 'Failed to apply inner join for aggregated field value: primary key must be a string' , [ 'source_table' => $ config -> getTable ( ) -> getAlias ( ) , 'target_table' => $ table -> getAlias ( ) , 'primar_key' => $ table -> getPrimaryKey ( ) , 'association' => $ association -> getName ( ) ] ) ; return $ q ; } $ entity = $ config -> getEntity ( ) ; return $ q -> where ( [ $ association -> getTarget ( ) -> aliasField ( $ primaryKey ) => $ entity -> get ( $ primaryKey ) ] ) ; } ) ; return $ query ; }
Aggregator query is joined whenever the entity instance is set, meaning
that the results will be limited to the entity's associated records.

@param \CsvMigrations\Aggregator\AggregatorInterface $aggregator Aggregator instance
@param \Cake\Datasource\QueryInterface $query Query object
@return \Cake\Datasource\QueryInterface
Aggregator query is joined whenever the entity instance is set meaning that the results will be limited to the entity s associated records .