public function groupVersions($results)
    {
        $property = $this->versionAssociation()->getProperty();

        return $results->map(function (EntityInterface $row) use ($property) {
            $versionField = $this->_config['versionField'];
            $versions = (array)$row->get($property);
            $grouped = new Collection($versions);

            $result = [];
            foreach ($grouped->combine('field', 'content', 'version_id') as $versionId => $keys) {
                $entityClass = $this->_table->getEntityClass();
                $versionData = [
                    $versionField => $versionId
                ];

                $keys = $this->_convertFieldsToType($keys, 'toPHP');

                /* @var \Cake\Datasource\EntityInterface $versionRow */
                $versionRow = $grouped->match(['version_id' => $versionId])->first();

                foreach ($this->_config['additionalVersionFields'] as $mappedField => $field) {
                    if (!is_string($mappedField)) {
                        $mappedField = 'version_' . $field;
                    }
                    $versionData[$mappedField] = $versionRow->get($field);
                }

                $version = new $entityClass($keys + $versionData, [
                    'markNew' => false,
                    'useSetters' => false,
                    'markClean' => true
                ]);
                $result[$versionId] = $version;
            }

            $options = ['setter' => false, 'guard' => false];
            $row->set('_versions', $result, $options);
            unset($row[$property]);
            $row->clean();

            return $row;
        });
    }
public function groupVersions($results)
    {
        $property = $this->versionAssociation()->getProperty();

        return $results->map(function (EntityInterface $row) use ($property) {
            $versionField = $this->_config['versionField'];
            $versions = (array)$row->get($property);
            $grouped = new Collection($versions);

            $result = [];
            foreach ($grouped->combine('field', 'content', 'version_id') as $versionId => $keys) {
                $entityClass = $this->_table->getEntityClass();
                $versionData = [
                    $versionField => $versionId
                ];

                $keys = $this->_convertFieldsToType($keys, 'toPHP');

                /* @var \Cake\Datasource\EntityInterface $versionRow */
                $versionRow = $grouped->match(['version_id' => $versionId])->first();

                foreach ($this->_config['additionalVersionFields'] as $mappedField => $field) {
                    if (!is_string($mappedField)) {
                        $mappedField = 'version_' . $field;
                    }
                    $versionData[$mappedField] = $versionRow->get($field);
                }

                $version = new $entityClass($keys + $versionData, [
                    'markNew' => false,
                    'useSetters' => false,
                    'markClean' => true
                ]);
                $result[$versionId] = $version;
            }

            $options = ['setter' => false, 'guard' => false];
            $row->set('_versions', $result, $options);
            unset($row[$property]);
            $row->clean();

            return $row;
        });
    }
public function groupVersions ( $ results ) { $ property = $ this -> versionAssociation ( ) -> getProperty ( ) ; return $ results -> map ( function ( EntityInterface $ row ) use ( $ property ) { $ versionField = $ this -> _config [ 'versionField' ] ; $ versions = ( array ) $ row -> get ( $ property ) ; $ grouped = new Collection ( $ versions ) ; $ result = [ ] ; foreach ( $ grouped -> combine ( 'field' , 'content' , 'version_id' ) as $ versionId => $ keys ) { $ entityClass = $ this -> _table -> getEntityClass ( ) ; $ versionData = [ $ versionField => $ versionId ] ; $ keys = $ this -> _convertFieldsToType ( $ keys , 'toPHP' ) ; /* @var \Cake\Datasource\EntityInterface $versionRow */ $ versionRow = $ grouped -> match ( [ 'version_id' => $ versionId ] ) -> first ( ) ; foreach ( $ this -> _config [ 'additionalVersionFields' ] as $ mappedField => $ field ) { if ( ! is_string ( $ mappedField ) ) { $ mappedField = 'version_' . $ field ; } $ versionData [ $ mappedField ] = $ versionRow -> get ( $ field ) ; } $ version = new $ entityClass ( $ keys + $ versionData , [ 'markNew' => false , 'useSetters' => false , 'markClean' => true ] ) ; $ result [ $ versionId ] = $ version ; } $ options = [ 'setter' => false , 'guard' => false ] ; $ row -> set ( '_versions' , $ result , $ options ) ; unset ( $ row [ $ property ] ) ; $ row -> clean ( ) ; return $ row ; } ) ; }
Modifies the results from a table find in order to merge full version records
into each entity under the `_versions` key

@param \Cake\Datasource\ResultSetInterface $results Results to modify.
@return \Cake\Collection\CollectionInterface
Modifies the results from a table find in order to merge full version records into each entity under the _versions key