In my picture entity I have an image attribute. (The other attributes are about alt, style etc. ). I noticed that attribute was not set as nullable= false. I decided to change that and after doing a doctrine schema update I noticed the column image_id is still set as nullable.
This led me to rethink my design and to set the Picture entity as extending from Image entity instead. I will try it next. I usually avoid class inheritance with my file related entities in Doctrine because it tend to cause too many problems.
However I would like to know. Is it expected behaviour from doctrine? SO far my One to One relationships have all been set to nullable. Is it impossible to make them not nullable? It would make sense since two closely related entities may be better off to be made one entity. However I would think this kind of concern should be left up to the developer's choice. As in my case, as I am reluctant to use inheritance on image entity.
the official documentation is not really explicit even though all examples show nullable foreign keys.
Here's the code:
/**
* @var
*
* @ORM\OneToOne(targetEntity="AnyRoutes\SiteBundle\Entity\Image", cascade={"persist", "remove"})
* @@ORM\JoinColumn(name="image_id", referencedColumnName="id", nullable=false)
*/
private $image;
@@ORM\JoinColumn(name="image_id", referencedColumnName="id", nullable=false)
check if removing redundant @ in @@ORM\ will help