网站建设对我有什么好处,网站首页被k 做跳转,济宁梵盛科技网站建设,湖南益阳我已经设置了一个包含测试对象的包,该对象包含许多testQuestion对象,每个对象都是一个问题和给定的答案(如果没有答案则为0).从树枝上我希望能够从测试对象中获取信息,说明有多少问题以及已经回答了多少问题.我创建了一个查询来将其从数据库中拉出来,在测试实体中我创建了2个新…我已经设置了一个包含测试对象的包,该对象包含许多testQuestion对象,每个对象都是一个问题和给定的答案(如果没有答案则为0).从树枝上我希望能够从测试对象中获取信息,说明有多少问题以及已经回答了多少问题.我创建了一个查询来将其从数据库中拉出来,在测试实体中我创建了2个新属性来存储问题的数量和回答的数量.我创建了一个查询所在的TestRepository. Test对象检查对象是否设置了值,如果没有,则在需要时加载它,因为我不总是需要这些信息.但是我仍然坚持如何将存储库代码链接到测试对象,既调用repo函数又调用repo函数将值保存到相关的Test对象.ACME / Quizbundle /测试/ test.php的namespace Acme\QuizBundle\Entity;use Doctrine\ORM\Mapping as ORM;use Acme\QuizBundle\Entity\TestRepository;/*** ORM\Entity(repositoryClassAcme\QuizBundle\Entity\TestRepository)* ORM\Table(nametest)*/class Test {protected $numQuestions null;protected $numQuestionsAnswered null;public function getNumQuestionsAnswered () {if (is_null($this-numQuestionsAnswered)) {$repository $this-getEntityManager()-getRepository(\AcmeQuizBundle\Test);$values $repository-calculateNumQuestions();}return $this-numQuestionsAnswered;}Acme / Quizbundle / Test / TestRepository.php(有一个getNumQuestions()的匹配方法)namespace Acme\QuizBundle\Entity;use Doctrine\ORM\EntityRepository;class TestRepository extends EntityRepository {private function calculateNumQuestions() {$qb $this-getEntityManager()-createQueryBuilder();$query $this-getEntityManager()-createQueryBuilder()-select(COUNT(id))-from(testquestion, tq)-where(tq.test_id :id)-setParameter(id, $this-getId())-getQuery();$result $query-getSingleScalarResult();var_dump($result);}