I'm trying to get a specific field in one of my entity classes to appear on my dropdown on my form. The entities do have a one to one relation, though the field I'm trying to retrieve on to my form is not the one related to the other class.
To make things simpler, I'd also like for only the distinct values of that field be shown in the dropdown. I've tried things similar to this: How to select distinct query using symfony2 doctrine query builder? but haven't gotten it to work. I've produced errors such as "Warning: spl_object_hash() expects parameter 1 to be object, string given"
Below is what I've written so far...
In the Form's class...
$builder
->add('typeOfPosition', EntityType::class, array(
'class' => Choices::class,
'label' => 'Type of Position: ',
'query_builder' => function(EntityRepository $er){
return $er->createQueryBuilder('c')
->select('DISTINCT c.type');
},
And the entity that the form is on:
/**
* @ORM\OneToOne(targetEntity="Position", inversedBy="division")
* @ORM\JoinColumn(name="position", referencedColumnName="id")
*/
private $position;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255)
*/
private $type;
And it's relation entity:
/**
* @var string
*
* @ORM\OneToOne(targetEntity="Choices", mappedBy="position")
*/
private $division;