Schema error not caught by validate: Column & JoinColumn #5219

Open
opened 2026-01-22 15:01:48 +01:00 by admin · 0 comments
Owner

Originally created by @pbowyer on GitHub (Aug 16, 2016).

If I make a mistake and use the following column definition:

    /**
     * @var User
     * @ORM\Column(type="integer")
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
     */
    private $user;

The table is created without issue, but the foreign key is omitted.

Running doctrine:schema:validate does not produce a warning, so all appears good.

This silent behaviour is not good (it took a long time to figure out the bug), and I would like to improve this. Three possible fixes are:

  1. When JoinColumn is set, silently ignore the Column definition
  2. Produce a warning only when running doctrine:schema:validate
  3. Produce a warning when running doctrine:schema:validate and when creating/updating tables

What would the team endorse?

For those not working with D2 every day, the correct code is as follows:

    /**
     * @var User
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
     */
    private $user;
Originally created by @pbowyer on GitHub (Aug 16, 2016). If I make a mistake and use the following column definition: ``` /** * @var User * @ORM\Column(type="integer") * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User") * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE") */ private $user; ``` The table is created without issue, but the foreign key is omitted. Running `doctrine:schema:validate` does not produce a warning, so all appears good. This silent behaviour is not good (it took a long time to figure out the bug), and I would like to improve this. Three possible fixes are: 1. When `JoinColumn` is set, silently ignore the `Column` definition 2. Produce a warning only when running `doctrine:schema:validate` 3. Produce a warning when running `doctrine:schema:validate` and when creating/updating tables What would the team endorse? _For those not working with D2 every day, the correct code is as follows:_ ``` /** * @var User * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User") * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE") */ private $user; ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5219