How to query for models containing all given values in an array field? [Doctrine ORM and ODM QueryBuilder]
Date : March 29 2020, 07:55 AM
it should still fix some issue I was misled by the array type mapping name. If you read carefully the docs, you will learn that there is no such database type as array. So what type is array mapped to? The anwser is text. Which means you can do LIKE operations on it (although, these may cause some performance impact). $qb->where($qb->expr()->andX(
$qb->expr()->like('tags', '?1'),
$qb->expr()->like('tags', '?2'),
$qb->expr()->like('tags', '?3')
))->setParameters(array(
1 => '%"a"%',
2 => '%"b"%',
3 => '%"c"%'
));
|
Doctrine DQL to QueryBuilder
Tag : mysql , By : Dominique Vocat
Date : March 29 2020, 07:55 AM
will help you Now that you clarified what you want to do, I would suggest using an 'entity' field type on your form that connects to your QuestionContent entity. // don't forget the use statement for your repository up top
use Your\VswSystemCmsBundle\Repository\QuestionContentRepository;
// in buildForm() (this assumes you have $pageId set properly)
$builder
->add('questionContent', 'entity', array(
'class' => 'VswSystemCmsBundle:QuestionContent',
'property' => 'questionForForm',
'query_builder' => function(QuestionContentRepository $repo) use ($pageId) {
return $repo->findNotAttachedQuestions($pageId);
},
))
;
// this is Your\VswSystemCmsBundle\Repository\QuestionContentRepository class
public function findNotAttachedQuestions($pageId)
{
$subQuery = $this->createQuery("
SELECT fq.questioncontent_id
FROM VswSystemCmsBundle:FaqPageQuestionContent fq
WHERE fq.faqcontentpage_id = :page_id
")
->setParameter('page_id', $pageId)
;
return $this->createQueryBuilder('q')
->where($qb->expr()->notIn('q.id', $subQuery))
;
}
// this is Your\VswSystemCmsBundle\Entity\QuestionContent class
public function getQuestionForForm()
{
return substr($this->getQuestion(), 0, 30);
}
|
Doctrine find() and querybuilder() return different result in PHPUnit test
Date : March 29 2020, 07:55 AM
Hope that helps diagnosis / explanation I assume* you already created the User object you're editing via crawler before in that function and checked that it is there. This leads to it being a managed entity.
|
How to have doctrine querybuilder with where not clause return values when null
Tag : mysql , By : lhoBas
Date : March 29 2020, 07:55 AM
|
Doctrine: ORM QueryBuilder or DBAL QueryBuilder
Date : March 29 2020, 07:55 AM
|