Published on

Symfony2 Doctrine ManyToOne as required field using join column


If you want a ManyToOne relation to be required, you have to include a join column. Without this column there will not be any reference to the other object in the database, and without a foreign key to this other object the doctrine constraints on this object cannot be created.


-   @ORM\ManyToOne(targetEntity="Package", inversedBy="users")
-   @ORM\JoinColumn(name="package_id", referencedColumnName="id", nullable=false)
    private $package;