我目前正在开展语言评估项目,使您能够以您想要的语言参加考试并评估您的水平.我使用Symfony2框架并与Doctrine2一起使用.我的问题是以下问题:
我有两个实体考试和问题由多对多关系链接(考试是所有者).每个考试都可以与几个问题相关,每个问题都可以与几个考试相关.
这是我的代码:
考试实体
/**
* Exam
*
* @ORM\Table(name="cids_exam")
* @ORM\Entity(repositoryClass="LA\AdminBundle\Entity\ExamRepository")
*/
class Exam
{
...
/**
* @ORM\ManyToMany(targetEntity="LA\AdminBundle\Entity\Question", cascade={"persist"})
* @ORM\JoinTable(name="cids_exam_question")
*/
private $questions;
...
/**
* Constructor
*/
public function __construct()
{
$this->questions = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add questions
*
* @param \LA\AdminBundle\Entity\Question $questions
* @return Exam
*/
public function addQuestion(\LA\AdminBundle\Entity\Question $questions)
{
$this->questions[] = $questions;
return $this;
}
/**
* Remove questions
*
* @param \LA\AdminBundle\Entity\Question $questions
*/
public function removeQuestion(\LA\AdminBundle\Entity\Question $questions)
{
$this->questions->removeElement($questions); …Run Code Online (Sandbox Code Playgroud)