我是Symfony 2的新手,我有一个测验E由测验A,B,C和C组成的场景。 D.这些存储为测验E的子规则。我正在尝试查询以查找测验E的所有子测验的所有问题,但它只返回测验答案A.我的代码:
$subQuizesString = '';
foreach($quiz - > getSubQuizes() as $key = > $quiz)
$subQuizesString. = $quiz - > getId().',';
$subQuizesString = rtrim($subQuizesString, ',');
$query = $em - > createQuery(
'SELECT question
FROM CriticalReadingQuizBundle:Question question
WHERE question.quiz in (:quizes) AND question.active = true
ORDER BY question.orderIndex, question.quiz, question.id') - > setParameter('quizes', $subQuizesString);
$questions = $query - > getResult();
首先,我想废除编译subQuizesString,因为我觉得在Symfony2中这应该是不必要的(但我不知道如何),其次(可能更重要的是),我想知道为什么我是只收到问答A的问题。
与往常一样,您的帮助很有价值,非常感谢。
答案 0 :(得分:0)
尝试这种方式:
$subQuizesArray = array();
foreach($quiz - > getSubQuizes() as $key = > $quiz) {
$subQuizesArray[] = $quiz - > getId();
}
$query = $em - > createQuery(
'SELECT question
FROM CriticalReadingQuizBundle:Question question
WHERE question.quiz IN :quizes AND question.active = true
ORDER BY question.orderIndex, question.quiz, question.id') - > setParameter('quizes', $subQuizesArray);
$questions = $query - > getResult();