application/Espo/Core/Utils/Database/Schema/Converter.php
protected function prepareManyMany($entityName, $relationParams, $tables)
    {
        $tableName = Util::toUnderScore($relationParams['relationName']);

        if ($this->getSchema()->hasTable($tableName)) {
            $GLOBALS['log']->debug('DBAL: Table ['.$tableName.'] exists.');
            return $this->getSchema()->getTable($tableName);
        }

        $table = $this->getSchema()->createTable($tableName);
        $table->addColumn('id', 'int', $this->getDbFieldParams(array(
            'type' => 'id',
            'len' => $this->defaultLength['int'],
            'autoincrement' => true,
        )));

        //add midKeys to a schema
        $uniqueIndex = array();
        foreach($relationParams['midKeys'] as $index => $midKey) {

            $columnName = Util::toUnderScore($midKey);
            $table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array(
                'type' => 'foreignId',
                'len' => $this->idParams['len'],
            )));
            $table->addIndex(array($columnName));

            $uniqueIndex[] = $columnName;
        }
        //END: add midKeys to a schema

        //add additionalColumns
        if (!empty($relationParams['additionalColumns'])) {
            foreach($relationParams['additionalColumns'] as $fieldName => $fieldParams) {

                if (!isset($fieldParams['type'])) {
                    $fieldParams = array_merge($fieldParams, array(
                        'type' => 'varchar',
                        'len' => $this->defaultLength['varchar'],
                    ));
                }

                $table->addColumn(Util::toUnderScore($fieldName), $fieldParams['type'], $this->getDbFieldParams($fieldParams));
            }
        } //END: add additionalColumns

        //add unique indexes
        if (!empty($relationParams['conditions'])) {
            foreach ($relationParams['conditions'] as $fieldName => $fieldParams) {
                $uniqueIndex[] = Util::toUnderScore($fieldName);
            }
        }

        if (!empty($uniqueIndex)) {
            $table->addUniqueIndex($uniqueIndex);
        }
        //END: add unique indexes

        $table->addColumn('deleted', 'bool', $this->getDbFieldParams(array(
            'type' => 'bool',
            'default' => false,
        )));

        $table->setPrimaryKey(array("id"));

        return $table;
    }
protected function prepareManyMany($entityName, $relationParams, $tables)
    {
        $tableName = Util::toUnderScore($relationParams['relationName']);

        if ($this->getSchema()->hasTable($tableName)) {
            $GLOBALS['log']->debug('DBAL: Table ['.$tableName.'] exists.');
            return $this->getSchema()->getTable($tableName);
        }

        $table = $this->getSchema()->createTable($tableName);
        $table->addColumn('id', 'int', $this->getDbFieldParams(array(
            'type' => 'id',
            'len' => $this->defaultLength['int'],
            'autoincrement' => true,
        )));

        //add midKeys to a schema
        $uniqueIndex = array();
        foreach($relationParams['midKeys'] as $index => $midKey) {

            $columnName = Util::toUnderScore($midKey);
            $table->addColumn($columnName, $this->idParams['dbType'], $this->getDbFieldParams(array(
                'type' => 'foreignId',
                'len' => $this->idParams['len'],
            )));
            $table->addIndex(array($columnName));

            $uniqueIndex[] = $columnName;
        }
        //END: add midKeys to a schema

        //add additionalColumns
        if (!empty($relationParams['additionalColumns'])) {
            foreach($relationParams['additionalColumns'] as $fieldName => $fieldParams) {

                if (!isset($fieldParams['type'])) {
                    $fieldParams = array_merge($fieldParams, array(
                        'type' => 'varchar',
                        'len' => $this->defaultLength['varchar'],
                    ));
                }

                $table->addColumn(Util::toUnderScore($fieldName), $fieldParams['type'], $this->getDbFieldParams($fieldParams));
            }
        } //END: add additionalColumns

        //add unique indexes
        if (!empty($relationParams['conditions'])) {
            foreach ($relationParams['conditions'] as $fieldName => $fieldParams) {
                $uniqueIndex[] = Util::toUnderScore($fieldName);
            }
        }

        if (!empty($uniqueIndex)) {
            $table->addUniqueIndex($uniqueIndex);
        }
        //END: add unique indexes

        $table->addColumn('deleted', 'bool', $this->getDbFieldParams(array(
            'type' => 'bool',
            'default' => false,
        )));

        $table->setPrimaryKey(array("id"));

        return $table;
    }
protected function prepareManyMany ( $ entityName , $ relationParams , $ tables ) { $ tableName = Util :: toUnderScore ( $ relationParams [ 'relationName' ] ) ; if ( $ this -> getSchema ( ) -> hasTable ( $ tableName ) ) { $ GLOBALS [ 'log' ] -> debug ( 'DBAL: Table [' . $ tableName . '] exists.' ) ; return $ this -> getSchema ( ) -> getTable ( $ tableName ) ; } $ table = $ this -> getSchema ( ) -> createTable ( $ tableName ) ; $ table -> addColumn ( 'id' , 'int' , $ this -> getDbFieldParams ( array ( 'type' => 'id' , 'len' => $ this -> defaultLength [ 'int' ] , 'autoincrement' => true , ) ) ) ; //add midKeys to a schema $ uniqueIndex = array ( ) ; foreach ( $ relationParams [ 'midKeys' ] as $ index => $ midKey ) { $ columnName = Util :: toUnderScore ( $ midKey ) ; $ table -> addColumn ( $ columnName , $ this -> idParams [ 'dbType' ] , $ this -> getDbFieldParams ( array ( 'type' => 'foreignId' , 'len' => $ this -> idParams [ 'len' ] , ) ) ) ; $ table -> addIndex ( array ( $ columnName ) ) ; $ uniqueIndex [ ] = $ columnName ; } //END: add midKeys to a schema //add additionalColumns if ( ! empty ( $ relationParams [ 'additionalColumns' ] ) ) { foreach ( $ relationParams [ 'additionalColumns' ] as $ fieldName => $ fieldParams ) { if ( ! isset ( $ fieldParams [ 'type' ] ) ) { $ fieldParams = array_merge ( $ fieldParams , array ( 'type' => 'varchar' , 'len' => $ this -> defaultLength [ 'varchar' ] , ) ) ; } $ table -> addColumn ( Util :: toUnderScore ( $ fieldName ) , $ fieldParams [ 'type' ] , $ this -> getDbFieldParams ( $ fieldParams ) ) ; } } //END: add additionalColumns //add unique indexes if ( ! empty ( $ relationParams [ 'conditions' ] ) ) { foreach ( $ relationParams [ 'conditions' ] as $ fieldName => $ fieldParams ) { $ uniqueIndex [ ] = Util :: toUnderScore ( $ fieldName ) ; } } if ( ! empty ( $ uniqueIndex ) ) { $ table -> addUniqueIndex ( $ uniqueIndex ) ; } //END: add unique indexes $ table -> addColumn ( 'deleted' , 'bool' , $ this -> getDbFieldParams ( array ( 'type' => 'bool' , 'default' => false , ) ) ) ; $ table -> setPrimaryKey ( array ( "id" ) ) ; return $ table ; }
Prepare a relation table for the manyMany relation

@param string $entityName
@param array $relationParams
@param array $tables

@return \Doctrine\DBAL\Schema\Table
Prepare a relation table for the manyMany relation