小编Rey*_*apt的帖子

Symfony One To Many不连接父母

我有一个包含3个实体的测验结构:

  • 测验有问题(OneToMany)
  • 问题有测验(ManyToOne)
  • 问题有答案(OneToMany)
  • 答案有疑问(ManyToOne)

代码看起来像这样:

测验实体

class Quiz
{    
    /**
     * @ORM\OneToMany(targetEntity="Question", mappedBy="quiz", cascade={"persist", "remove"})
     */
    private $questions;

    public function __construct() {
        $this->questions = new ArrayCollection();
    }

    public function addQuestion(\Cariboo\QuizBundle\Entity\Question $questions)
    {
        $questions->setQuiz( $this );
        // die(); Not dying here...
        $this->questions[] = $questions;

        return $this;
    }

    public function removeQuestion(\Cariboo\QuizBundle\Entity\Question $questions)
    {
        $this->questions->removeElement($questions);
    }

    public function getQuestions()
    {
        return $this->questions;
    }
}
Run Code Online (Sandbox Code Playgroud)

问题实体

class Question
{
    /**
     * @ORM\OneToMany(targetEntity="Answer", mappedBy="question", cascade={"persist", "remove"})
     */
    private $answers;

    /**
     * @ORM\ManyToOne(targetEntity="Cariboo\QuizBundle\Entity\Quiz", cascade={"persist"})
     */ …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

5
推荐指数
1
解决办法
148
查看次数

标签 统计

doctrine-orm ×1

php ×1

symfony ×1