A bit of a tricky one:
I have a form collection for the Entity Street
.
The collection items are the houses
. I need to order the houses in the collection by the room
I had tried to add @ORM\OrderBy({"room" = "ASC"})
but obviously without specifying the weight fields inside the Room Entity there is no way the collection will know.
Is what I am trying to do even possible?
Street.php
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="houses", mappedBy="street")
*/
protected $houses;
Houses.php
/**
* @var Room
*
* @ORM\ManyToOne(targetEntity="Room", inversedBy="house")
* @ORM\JoinColumn(name="room_id", referencedColumnName="id")
*/
private $room;
/**
* @var Street
*
* @ORM\ManyToOne(targetEntity="Street", inversedBy="houses")
* @ORM\JoinColumn(name="street_id", referencedColumnName="id")
*/
private $street;
HouseCollectionType.php
$builder
->add('houses', 'collection', array(
'type' => new HouseFieldsType(),
'allow_delete' => false,
))
;
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Bundle/Street'
));
}