doctrine/orm

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

Open

#4,824 opened on Oct 24, 2015

View on GitHub
 (1 comment) (4 reactions) (1 assignee)PHP (2,539 forks)batch import
BugHacktoberfest

Repository metrics

Stars
 (10,176 stars)
PR merge metrics
 (Avg merge 29d 6h) (13 merged PRs in 30d)

Description

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.

Contributor guide