I am using symfony2 and doctrine2 to develop a web app.
I have a form in the app that has a dropdown that is populated from an entity. I have configured a query_builder to filter the values in the dropdown field.
public function buildForm(FormBuilderInterface $builder, array $options) {
$centerId = $this->centerId;
$builder->add("glCode", "entity", array(
"class" => "MyBundle:GlCode",
"query_builder" => function(EntityRepository $er) use($centerId) {
return $er->createQueryBuilder("g")
->join("g.account", "a")
->where("g.id NOT IN (SELECT g2.id FROM MyBundle:OtherFixedCost c JOIN MyBundle:GlCode g2)")
}
));
This code is producing the error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got ')'
I am trying to do with the query builder the same thing I would do with the following DQL:
SELECT g FROM MyBundle:GlCode g
JOIN g.account a
WHERE g.id NOT IN (
SELECT g2.id FROM MyBundle:OtherFixedCost c INNER JOIN MyBundle:GlCode g2
)
I do not know if I am missing something, but apparently doesn't exist a way to use directly DQL in the form class. So, I am being forced to use QueryBuilder, but I am getting the above error.