NicolaPez
NicolaPez

Reputation: 587

Doctrine 2 - ManyToOne Nullable relation not work

I have a strange error, on my Symfony4 project. One of my relation is a ManyToOne with nullable true, like this:

class UserComic
{
 ...
/**
 * @ORM\Id
 * @ORM\ManyToOne(targetEntity="Series")
 * @ORM\JoinColumn(name="id_series", referencedColumnName="id", nullable=true)
 */
private $series;
...
}

then I try to create a new UserComic with the $series attribute set to NULL, but i receive this error:

"Entity of type App\Entity\UserComic is missing an assigned ID for field 'series'. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly."

As the field is not setted to nullable. Any advice?

Upvotes: 0

Views: 765

Answers (1)

JessGabriel
JessGabriel

Reputation: 1072

ID means UNIQ and NOT NULLABLE.

You are on a ManyToOne relatsionship (on the many side) that break the UNIQ property of ID

You set the joinColumn as nullable, that breaks the NOT NULLABLE PROPERTY

Upvotes: 0

Related Questions