protected function renameManyToOneExtendField(Schema $schema, QueryBag $queries, Table $table, $associationName) { $oldColumnName = 'field_' . $associationName . '_id'; if ($table->hasColumn($oldColumnName)) { $newColumnName = $this->nameGenerator->generateRelationColumnName($associationName); $this->renameExtension->renameColumn($schema, $queries, $table, $oldColumnName, $newColumnName); } }
/** * @param FieldConfigId $fieldId * * @return string */ protected function getManyToOneColumnName(FieldConfigId $fieldId) { $columnName = null; if ($this->configManager->hasConfig($fieldId->getClassName(), $fieldId->getFieldName())) { $columnName = $this->getFieldConfig($fieldId)->get('column_name'); } if (!$columnName) { $columnName = $this->nameGenerator->generateRelationColumnName($fieldId->getFieldName()); } return $columnName; }
/** * Adds many-to-one relation * * @param Schema $schema * @param Table|string $table A Table object or table name * @param string $associationName The name of a relation field * @param Table|string $targetTable A Table object or table name * @param string $targetColumnName A column name is used to show related entity * @param array $options * @param string $fieldType The field type. By default the field type is manyToOne, * but you can specify another type if it is based on manyToOne. * In this case this type should be registered * in entity_extend.yml under underlying_types section */ public function addManyToOneRelation(Schema $schema, $table, $associationName, $targetTable, $targetColumnName, array $options = [], $fieldType = RelationType::MANY_TO_ONE) { $this->ensureExtendFieldSet($options); $selfTableName = $this->getTableName($table); $selfTable = $this->getTable($table, $schema); $selfColumnName = $this->nameGenerator->generateRelationColumnName($associationName); $targetTableName = $this->getTableName($targetTable); $targetTable = $this->getTable($targetTable, $schema); $this->checkColumnsExist($targetTable, [$targetColumnName]); $this->addRelation($selfTable, $selfColumnName, $targetTable, ['notnull' => false], ['onDelete' => 'SET NULL']); $options[ExtendOptionsManager::TARGET_OPTION] = ['table_name' => $targetTableName, 'column' => $targetColumnName]; $options[ExtendOptionsManager::TYPE_OPTION] = $fieldType; $this->extendOptionsManager->setColumnOptions($selfTableName, $associationName, $options); }