src/CRUDlex/MySQLData.php
protected function enrichWithManyField(&$idToData, $manyField)
    {
        $queryBuilder     = $this->database->createQueryBuilder();
        $nameField        = $this->definition->getSubTypeField($manyField, 'many', 'nameField');
        $thisField        = $this->definition->getSubTypeField($manyField, 'many', 'thisField');
        $thatField        = $this->definition->getSubTypeField($manyField, 'many', 'thatField');
        $entity           = $this->definition->getSubTypeField($manyField, 'many', 'entity');
        $entityDefinition = $this->definition->getService()->getData($entity)->getDefinition();
        $entityTable      = $entityDefinition->getTable();
        $nameSelect       = $nameField !== null ? ', t2.`'.$nameField.'` AS name' : '';
        $queryBuilder
            ->select('t1.`'.$thisField.'` AS this, t1.`'.$thatField.'` AS id'.$nameSelect)
            ->from('`'.$manyField.'`', 't1')
            ->leftJoin('t1', '`'.$entityTable.'`', 't2', 't2.id = t1.`'.$thatField.'`')
            ->where('t1.`'.$thisField.'` IN (?)')
        ;
        $this->addSoftDeletionToQuery($entityDefinition, $queryBuilder);
        $queryBuilder->setParameter(0, array_keys($idToData), Connection::PARAM_STR_ARRAY);
        $queryResult    = $queryBuilder->execute();
        $manyReferences = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
        foreach ($manyReferences as $manyReference) {
            $entityId = $manyReference['this'];
            unset($manyReference['this']);
            $idToData[$entityId][$manyField][] = $manyReference;
        }
    }
protected function enrichWithManyField(&$idToData, $manyField)
    {
        $queryBuilder     = $this->database->createQueryBuilder();
        $nameField        = $this->definition->getSubTypeField($manyField, 'many', 'nameField');
        $thisField        = $this->definition->getSubTypeField($manyField, 'many', 'thisField');
        $thatField        = $this->definition->getSubTypeField($manyField, 'many', 'thatField');
        $entity           = $this->definition->getSubTypeField($manyField, 'many', 'entity');
        $entityDefinition = $this->definition->getService()->getData($entity)->getDefinition();
        $entityTable      = $entityDefinition->getTable();
        $nameSelect       = $nameField !== null ? ', t2.`'.$nameField.'` AS name' : '';
        $queryBuilder
            ->select('t1.`'.$thisField.'` AS this, t1.`'.$thatField.'` AS id'.$nameSelect)
            ->from('`'.$manyField.'`', 't1')
            ->leftJoin('t1', '`'.$entityTable.'`', 't2', 't2.id = t1.`'.$thatField.'`')
            ->where('t1.`'.$thisField.'` IN (?)')
        ;
        $this->addSoftDeletionToQuery($entityDefinition, $queryBuilder);
        $queryBuilder->setParameter(0, array_keys($idToData), Connection::PARAM_STR_ARRAY);
        $queryResult    = $queryBuilder->execute();
        $manyReferences = $queryResult->fetchAll(\PDO::FETCH_ASSOC);
        foreach ($manyReferences as $manyReference) {
            $entityId = $manyReference['this'];
            unset($manyReference['this']);
            $idToData[$entityId][$manyField][] = $manyReference;
        }
    }
protected function enrichWithManyField ( & $ idToData , $ manyField ) { $ queryBuilder = $ this -> database -> createQueryBuilder ( ) ; $ nameField = $ this -> definition -> getSubTypeField ( $ manyField , 'many' , 'nameField' ) ; $ thisField = $ this -> definition -> getSubTypeField ( $ manyField , 'many' , 'thisField' ) ; $ thatField = $ this -> definition -> getSubTypeField ( $ manyField , 'many' , 'thatField' ) ; $ entity = $ this -> definition -> getSubTypeField ( $ manyField , 'many' , 'entity' ) ; $ entityDefinition = $ this -> definition -> getService ( ) -> getData ( $ entity ) -> getDefinition ( ) ; $ entityTable = $ entityDefinition -> getTable ( ) ; $ nameSelect = $ nameField !== null ? ', t2.`' . $ nameField . '` AS name' : '' ; $ queryBuilder -> select ( 't1.`' . $ thisField . '` AS this, t1.`' . $ thatField . '` AS id' . $ nameSelect ) -> from ( '`' . $ manyField . '`' , 't1' ) -> leftJoin ( 't1' , '`' . $ entityTable . '`' , 't2' , 't2.id = t1.`' . $ thatField . '`' ) -> where ( 't1.`' . $ thisField . '` IN (?)' ) ; $ this -> addSoftDeletionToQuery ( $ entityDefinition , $ queryBuilder ) ; $ queryBuilder -> setParameter ( 0 , array_keys ( $ idToData ) , Connection :: PARAM_STR_ARRAY ) ; $ queryResult = $ queryBuilder -> execute ( ) ; $ manyReferences = $ queryResult -> fetchAll ( \ PDO :: FETCH_ASSOC ) ; foreach ( $ manyReferences as $ manyReference ) { $ entityId = $ manyReference [ 'this' ] ; unset ( $ manyReference [ 'this' ] ) ; $ idToData [ $ entityId ] [ $ manyField ] [ ] = $ manyReference ; } }
Enriches the given mapping of entity id to raw entity data with some many-to-many data.

@param array $idToData
a reference to the map entity id to raw entity data
@param $manyField
the many field to enrich data with
Enriches the given mapping of entity id to raw entity data with some many - to - many data .