I want to create a form select field which looks like this:
<select>
<option value="product.product_id">product_details.detail_name</option>
etc...
</select>
The value is not the problem, the problem is with the label.
I have a product entity and a productDetails entity which contains translated data about a product.
So, in my form type class, in the buildForm method, I have this:
$builder->add('product', 'entity', array(
'class' => 'MyBundle:Product',
'property' => 'details.detail_name',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('p')
->select('p, pd')
->join('p.details', 'pd')
->where('pd.language_id = :lang')
->setParameter('lang', 'en');
}));
I want the property to be the details.detail_name.
I tried different values for this property value. Like 'details.detail_name', 'pd.detail_name' and 'p.details.detail_name'.
But it seems to be impossible to get the property to display the detail name.
When I use to above mentioned code, I get this error:
Neither property "detail_name" nor method "getDetailName()" nor method "isDetailName()" exists in class "Doctrine\ORM\PersistentCollection"
This getDetailName() method does exist in the ProductDetails entity, and I have checked the entities and they all seem to be okay. Also, they work just fine when I use these entities outside the form.
I also tried to execute the resulting query directly on my database, and it gives me the expected results. The detail_name are in the right language.
So, can somebody help me on how to make the select choice list I want, with a joined query?