Q:

Expected argument of type "object or array", "integer" given

I'm facing an error when building an form item using an entity type with a custom query.  Without the custom query it worked fine... so I suppose that the problem lies somewhere in the query. 
That's the excerpt from type.php
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('Event', 'entity', array(
                'class' => 'EventBundle:Event',
                'query_builder' => function(EntityRepository $er){
                    return $er->createQueryBuilder('e')
                        ->select('e.id, g.title')
                        ->leftJoin('e. Group g')
                        ->orderBy('e.start', 'DESC');
                },
                'property' => 'title',
                'empty_value' => 'Please choose an event...'
            ))

I can see that the query works fine... this are the values that create the exception. 

PropertyAccessor ->readPropertiesUntil ('77', object(PropertyPath),
  '1') in
  /vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php
  at line 49

Thanks for any help

A:

The "query_builder" closure option expects an object or an array as return.  Your QueryBuilder selects the Id of the Event and the title of the Group, which are not objects. 
Try this: 
$builder
        ->add('Event', 'entity', array(
            'class' => 'EventBundle:Event',
            'query_builder' => function(EntityRepository $er){
                return $er->createQueryBuilder('e')
                    ->select('e')
                    ->leftJoin('e. Group', 'g')
                    ->orderBy('e.start', 'DESC');
            },
            'property' => 'title',
            'empty_value' => 'Please choose an event...'
        ))

