Skip to content

Instantly share code, notes, and snippets.

@rela589n
Created May 22, 2024 17:29
Show Gist options
  • Save rela589n/5073b6c20c4b0609314a0d5dbfb69b0e to your computer and use it in GitHub Desktop.
Save rela589n/5073b6c20c4b0609314a0d5dbfb69b0e to your computer and use it in GitHub Desktop.
Doctrine stop removing foreign key
#[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