Skip to content

Update outdated examples in documentation (schema-representation) #6970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 4.2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions docs/en/reference/schema-representation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ example shows:
$myForeign = $schema->createTable("my_foreign");
$myForeign->addColumn("id", "integer");
$myForeign->addColumn("user_id", "integer");
$myForeign->addForeignKeyConstraint($myTable, ["user_id"], ["id"], ["onUpdate" => "CASCADE"]);
$myForeign->addForeignKeyConstraint($myTable->getName(), ["user_id"], ["id"], ["onUpdate" => "CASCADE"]);

$connection = \Doctrine\DBAL\DriverManager::getConnection([/*...*/]);
$myPlatform = $connection->getDatabasePlatform();

$queries = $schema->toSql($myPlatform); // get queries to create this schema.
$dropSchema = $schema->toDropSql($myPlatform); // get queries to safely delete this schema.
Expand All @@ -45,19 +48,11 @@ use the ``Comparator`` class to get instances of ``SchemaDiff``,
foreign key, sequence and index changes.

.. code-block:: php

<?php
/*...*/
$schemaManager = $connection->createSchemaManager();
$comparator = $schemaManager->createComparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);

$queries = $schemaDiff->toSql($myPlatform); // queries to get from one to another schema.
$saveQueries = $schemaDiff->toSaveSql($myPlatform);

The Save Diff mode is a specific mode that prevents the deletion of
tables and sequences that might occur when making a diff of your
schema. This is often necessary when your target schema is not
complete but only describes a subset of your application.
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);

All methods that generate SQL queries for you make much effort to
get the order of generation correct, so that no problems will ever
Expand Down