DDC-3961: orm:validate-schema exits with exception instead of reporting ManyToMany mapping error #4842

Open
opened 2026-01-22 14:50:23 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Oct 24, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user benjamin:

When using bi-directional many-to-many associations, and forgetting to use mappedBy and indexedBy, the error is not reported when validating the mapping (orm:validate-schema --skip-sync).

Example code:

    class Cuisine {
        /****
         * @ManyToMany(targetEntity="Dish")
         * @ORM\JoinTable(name="CuisineDish", ...)
         */
        protected $dishes;
    }

    class Dish {
        /****
         * @ORM\ManyToMany(targetEntity="Cuisine")
         * @ORM\JoinTable(name="CuisineDish", ...)
         */
        protected $cuisines;
    }

Furthermore, it triggers an exception when validating the sync with the database (orm:validate-schema [--skip-mapping]).

The exception is:

{quote}
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'mydb.CuisineDish' already exists.
{quote}

This exception should not be thrown, and its message is really confusing to the end user, as it suggests that Doctrine is attempting to create a table in the database, whereas this action is read-only.

Originally created by @doctrinebot on GitHub (Oct 24, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user benjamin: When using bi-directional many-to-many associations, and forgetting to use `mappedBy` and `indexedBy`, the error is not reported when validating the mapping (`orm:validate-schema --skip-sync`). Example code: ``` class Cuisine { /**** * @ManyToMany(targetEntity="Dish") * @ORM\JoinTable(name="CuisineDish", ...) */ protected $dishes; } class Dish { /**** * @ORM\ManyToMany(targetEntity="Cuisine") * @ORM\JoinTable(name="CuisineDish", ...) */ protected $cuisines; } ``` Furthermore, it triggers an exception when validating the sync with the database (`orm:validate-schema [--skip-mapping]`). The exception is: {quote} [Doctrine\DBAL\Schema\SchemaException] The table with name 'mydb.CuisineDish' already exists. {quote} This exception should not be thrown, and its message is really confusing to the end user, as it suggests that Doctrine is attempting to create a table in the database, whereas this action is read-only.
admin added the BugHacktoberfest labels 2026-01-22 14:50:23 +01:00
Author
Owner

@beberlei commented on GitHub (Feb 16, 2020):

The check that is missing here in the validate schema functionality is to see that two entities have many to many pointing to each other that both use the same join table name. If this happens its a violation.

@beberlei commented on GitHub (Feb 16, 2020): The check that is missing here in the validate schema functionality is to see that two entities have many to many pointing to each other that both use the same join table name. If this happens its a violation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4842