But it does not work with exception message:
Entit
This error means the attribute questionCategory
which is a relationship, is not managed by the EntityManager. For this to be done automatically, add a cascade-persist in your Doctrine Mapping for questionCategory
attribute:
Entity
/**
* Question
*
* @ORM\Table(name="question")
* @ORM\Entity
*/
class Question
{
//...
/**
* @ORM\ManyToOne(
* targetEntity="QualityBundle\Entity\QuestionCategory",
* cascade={"persist"}
* )
*/
private $questionCategory;
//...
}
This way, when you call $em->persist($question);
, the QuestionCategory
linked to your Question
will automatically be persisted as well.