Reputation: 2837
I would like to know how to use queryBuilder expression within a formBuilder.
The general use of query builder in formBuilder is :
$builder->add('client', EntityType::class, array(
'class'=>Entity::class,
'query_builder'=>function(EntityRepository $er) {
return $er->createQueryBuilder("e")
->where("e.active=1");
},
));
Now, I would like to use ->expr()->in()
within where
statement.
The problem is, unlike entity repository, $er->expr
doesn't works.
What should I do to access expr
within the where
statement?
Upvotes: 1
Views: 702
Reputation: 39470
You can access the expression builder accessing the EntityManager and then get the expression builder, as example:
$builder->add('client', EntityType::class, array(
'class'=>Entity::class,
'query_builder'=>function(EntityRepository $er) {
$expr = $er->getEntityManager()->getExpressionBuilder();
// ..
},
));
Hope this help
Upvotes: 2
Reputation: 1039
function (EntityRepository $repo) {
$qb = $repo->createQueryBuilder('e');
$qb
->andWhere($qb->expr()->in(...))
;
return $qb;
}
Upvotes: 1