I set up a form which includes a multiple expanded form
$builder->add('rooms', 'entity', array(
'class' => 'MyBundle:House',
'multiple' => true,
'expanded' => true,
'required' => false
));
The underlying class House has a rooms attribute defined as a many-to-many relation
/**
* @ORM\ManyToMany(targetEntity="RoomsType", cascade={"all"})
*/
private $rooms;
public function __construct()
{
$this->rooms = new \Doctrine\Common\Collections\ArrayCollection();
}
public function addRooms($room)
{
$this->rooms[] = $room;
}
public function getRooms()
{
return $this->rooms;
}
When I render the form
{{ form_row(form.rooms }}
and then submit the form, I meet the following exception: Expected argument of type 'array' 'string' given (500 Internal Server Error)
If the form is not configured as a expanded, no exception is raised and the binding between the form and the underlying object works fine.
Any idea ?
Your targetEntity for your relationship has an odd name of RoomsType. Are you certain your Entity is RoomsType and not just Rooms? I would expect your RoomsType to define the form for your Rooms entity