1
votes

I have this Symfony form with a ManyToMany relation working fine, it displays all the parties with the property name on the entity Party.

When submitted, it queries the database according to the parties that are selected and retrieves the persons that are invited to those parties.

public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder
            ->add('parties', 'entity', array(
                'class' => 'ProtoBundle:Party',
                'multiple' => true,
                'expanded' => false,
                'property' => 'name',
                'required' => false,));
}

with the parameter

'multiple' => 'true,

all the parties are displayed at the same time in a select drop down box (not what i want).

What I want is just to have one select tag with parameter

'empty_value' => 'choose a party'

, then when the user clicks on it, the values are displayed. Actually I can do this with the parameter

'multiple'=> false,

but the problem is that I get this error message:

Neither the property "parties" nor one of the methods "setParties()", "__set()" or "__call()" exist and have public access in class "Acme\ProtoBundle\Entity\Person".

Does anyone knows how to make this select tag working and bring me a detailed solution?

1

1 Answers

1
votes

In first of all you should get in consideration that if you really need many to many relation when you want simple select box without multiple select.

But...

in entity you will have to check if comming value is array, and that's it:

public function setParties($parties) 
{
    if (!is_array($parties)) {
        $parties = array($parties);
    }
    $this->parties = $parties;
}