I have a form builder where I am generating a select option. In this select I have to take out the elements that already exist in the database. For this I am creating a query builder. Now in this query builder I want to make a JOIN
to get a single row from the languages table for a specific language. The problem is that after I added this JOIN
symfony returns an access error:
Error: Cannot access private property XXX\DatabaseBundle\Entity\AttributeGroupLanguage::$id
Here is what I do:
$builder->add('attributeGroups', 'entity', array(
'class' => 'XXX\DatabaseBundle\Entity\AttributeGroup',
'choice_label' => 'name',
'query_builder' => function(EntityRepository $er) use ($existingAttributeGroups) {
return $er->createQueryBuilder('ag')
->addSelect('agl')
->join('XXXDatabaseBundle:AttributeGroupLanguage agl', 'WITH agl.attributeGroup = ag.id')
->where('ag.id NOT IN (:existingAttributeGroups)')
->andWhere('agl.language = :languageId')
->setParameters(
array(
'existingAttributeGroups' => ($existingAttributeGroups) ?: '',
'languageId' => 1 //german
)
);
},
'attr' => array(
'class' => 'attributeGroupsList',
'style' => 'width: 250px'
)
));
Add public getId() method to AttributeGroupLanguage entity.
public function getId(){
return $this->id;
}