protected function generateMorphToManyPivotTable($name, Annotation $annotation, EntityDefinition &$entityMetadata)
    {
        $morphName = $annotation->morphName;

        $tableName = ($annotation->pivotTable)
            ? $annotation->pivotTable
            : $this->generatePivotTablename($entityMetadata['class'], $annotation->relatedEntity, $annotation->inverse, $morphName);

        if ($annotation->inverse) {
            $pivotKey = $annotation->localPivotKey ?: $this->generateKey($entityMetadata['class']);
        } else {
            $pivotKey = $annotation->relatedPivotKey ?: $this->generateKey($annotation->relatedEntity);
        }

        $morphId = (! empty($annotation->localKey))
            ? $annotation->localKey
            : $morphName.'_id';

        $morphType = $morphName.'_type';

        return new TableDefinition([
            'name' => $tableName,
            'columns' => [
                $this->getModifiedPrimaryKeyColumn($entityMetadata['table'], [
                    'name' => $pivotKey,
                    'options' => [
                        'autoIncrement' => false
                    ]
                ]),
                $this->getModifiedPrimaryKeyColumn($entityMetadata['table'], [
                    'name' => $morphId,
                    'options' => [
                        'autoIncrement' => false
                    ]
                ]),
                new ColumnDefinition([
                    'name' => $morphType,
                    'type' => 'string',
                    'nullable' => false,
                    'default' => false,
                    'primary' => true,
                    'unique' => false,
                    'index' => false,
                    'options' => []
                ]),
            ]
        ]);
    }
protected function generateMorphToManyPivotTable($name, Annotation $annotation, EntityDefinition &$entityMetadata)
    {
        $morphName = $annotation->morphName;

        $tableName = ($annotation->pivotTable)
            ? $annotation->pivotTable
            : $this->generatePivotTablename($entityMetadata['class'], $annotation->relatedEntity, $annotation->inverse, $morphName);

        if ($annotation->inverse) {
            $pivotKey = $annotation->localPivotKey ?: $this->generateKey($entityMetadata['class']);
        } else {
            $pivotKey = $annotation->relatedPivotKey ?: $this->generateKey($annotation->relatedEntity);
        }

        $morphId = (! empty($annotation->localKey))
            ? $annotation->localKey
            : $morphName.'_id';

        $morphType = $morphName.'_type';

        return new TableDefinition([
            'name' => $tableName,
            'columns' => [
                $this->getModifiedPrimaryKeyColumn($entityMetadata['table'], [
                    'name' => $pivotKey,
                    'options' => [
                        'autoIncrement' => false
                    ]
                ]),
                $this->getModifiedPrimaryKeyColumn($entityMetadata['table'], [
                    'name' => $morphId,
                    'options' => [
                        'autoIncrement' => false
                    ]
                ]),
                new ColumnDefinition([
                    'name' => $morphType,
                    'type' => 'string',
                    'nullable' => false,
                    'default' => false,
                    'primary' => true,
                    'unique' => false,
                    'index' => false,
                    'options' => []
                ]),
            ]
        ]);
    }
protected function generateMorphToManyPivotTable ( $ name , Annotation $ annotation , EntityDefinition & $ entityMetadata ) { $ morphName = $ annotation -> morphName ; $ tableName = ( $ annotation -> pivotTable ) ? $ annotation -> pivotTable : $ this -> generatePivotTablename ( $ entityMetadata [ 'class' ] , $ annotation -> relatedEntity , $ annotation -> inverse , $ morphName ) ; if ( $ annotation -> inverse ) { $ pivotKey = $ annotation -> localPivotKey ? : $ this -> generateKey ( $ entityMetadata [ 'class' ] ) ; } else { $ pivotKey = $ annotation -> relatedPivotKey ? : $ this -> generateKey ( $ annotation -> relatedEntity ) ; } $ morphId = ( ! empty ( $ annotation -> localKey ) ) ? $ annotation -> localKey : $ morphName . '_id' ; $ morphType = $ morphName . '_type' ; return new TableDefinition ( [ 'name' => $ tableName , 'columns' => [ $ this -> getModifiedPrimaryKeyColumn ( $ entityMetadata [ 'table' ] , [ 'name' => $ pivotKey , 'options' => [ 'autoIncrement' => false ] ] ) , $ this -> getModifiedPrimaryKeyColumn ( $ entityMetadata [ 'table' ] , [ 'name' => $ morphId , 'options' => [ 'autoIncrement' => false ] ] ) , new ColumnDefinition ( [ 'name' => $ morphType , 'type' => 'string' , 'nullable' => false , 'default' => false , 'primary' => true , 'unique' => false , 'index' => false , 'options' => [ ] ] ) , ] ] ) ; }
Generate pivot table for a morphToMany relation.

@param string $name
@param \ProAI\Datamapper\Annotations\Annotation $annotation
@param \ProAI\Datamapper\Metadata\Definitions\Class $entityMetadata
@return \ProAI\Datamapper\Metadata\Definitions\Table
Generate pivot table for a morphToMany relation .