Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Invalid
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: ORM
-
Labels:None
Description
I have the following code:
$new = new InterviewReview(); $question = new InterviewReviewQuestion(); $new->addQuestion($question); $em->persist($new); $em->flush();
When i execute this code i have the following error:
An exception occurred while executing 'INSERT INTO interview_review_question (question, tags, created_at, interview_review_id) VALUES (?, ?, ?, ?)' with params {"1":"asdfg","2":"asdfg","3":null,"4":null}: Column 'interview_review_id' cannot be null
Here are my entities:
/** * InterviewReview * * @ORM\Table(name="interview_review") * @ORM\Entity */ class InterviewReview { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var Doctrine\Common\Collections\ArrayCollection * * @ORM\OneToMany(targetEntity="Absolvent\AbsolventBundle\Entity\InterviewReviewQuestion", cascade={"persist", "remove"}, mappedBy="interview_review") * @ORM\JoinColumn(name="interview_review", referencedColumnName="id") */ private $questions; /** * Add question * * @param \Absolvent\AbsolventBundle\Entity\InterviewReviewQuestion $question * @return InterviewReview */ public function addQuestion(\Absolvent\AbsolventBundle\Entity\InterviewReviewQuestion $question) { $this->questions[] = $question; return $this; } /** * Remove question * * @param \Absolvent\AbsolventBundle\Entity\InterviewReviewQuestion $question */ public function removeQuestion(\Absolvent\AbsolventBundle\Entity\InterviewReviewQuestion $question) { $this->questions->removeElement($question); } /** * Get questions * * @return \Doctrine\Common\Collections\Collection */ public function getQuestions() { return $this->questions; } } /** * InterviewReviewQuestion * * @ORM\Table(name="interview_review_question") * @ORM\Entity */ class InterviewReviewQuestion { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var Absolvent\AbsolventBundle\Entity\InterviewReview * * @ORM\ManyToOne(targetEntity="Absolvent\AbsolventBundle\Entity\InterviewReview", cascade={"persist", "remove"}, inversedBy="questions") * @ORM\JoinColumn(name="interview_review_id", referencedColumnName="id", nullable=false) */ private $interview_review; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set interview_review * * @param \Absolvent\AbsolventBundle\Entity\InterviewReview $interviewReview * @return InterviewReviewQuestion */ public function setInterviewReview(\Absolvent\AbsolventBundle\Entity\InterviewReview $interviewReview = null) { $this->interview_review = $interviewReview; return $this; } /** * Get interview_review * * @return \Absolvent\AbsolventBundle\Entity\InterviewReview */ public function getInterviewReview() { return $this->interview_review; } }
This problem is causing because the is no $question->setInterviewReview() called anywhere.
I know that i can call it inside addQuestion function, but is should work out of the box - isn't it?