Created
May 22, 2024 17:29
-
-
Save rela589n/5073b6c20c4b0609314a0d5dbfb69b0e to your computer and use it in GitHub Desktop.
Doctrine stop removing foreign key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[AsDoctrineListener(event: ToolEvents::postGenerateSchema)] | |
final readonly class QuestionForeignKeyListener | |
{ | |
/** @throws SchemaException */ | |
public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs): void | |
{ | |
$schema = $eventArgs->getSchema(); | |
$table = $schema->getTable('answers'); | |
$table->addForeignKeyConstraint('questions', ['question_id'], ['id'], name: 'your_custom_foreign_key'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment