1

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 ?

Brandon
  • 16,382
  • 12
  • 55
  • 88
queto putito
  • 253
  • 3
  • 15
  • 1
    Your code is a bit wrong. `$this->rooms = $room;` should be `$this->rooms[] = $room;` (if it's supposed to add a room). not sure whether it's the reason of your problem or not. – meze Jan 17 '12 at 07:38
  • no, it's a bad copy paste only, I modified the sample – queto putito Jan 17 '12 at 08:52

1 Answers1

0

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

DanF7
  • 171
  • 1
  • 2
  • 6