I would like to create a form for my entity named Order:
/** @ORM\Entity */
class Order {
//...
/**
* @ORM\OneToMany(targetEntity=Entry::class, mappedBy="order", orphanRemoval=true)
*/
private $entries;
//...
}
The Entry class looks like this:
/** @ORM\Entity */
class Entry {
//...
/**
* @ORM\ManyToOne(targetEntity=Product::class)
* @ORM\JoinColumn(nullable=false)
*/
private $product;
/**
* @ORM\Column(type="integer")
*/
private $count = 0;
//...
}
I already defined a type for Entry.
An Order has multiple Entry. I would like to make it possible to create the entries in the same form, where the Order is created. I can not use EntityType with 'multiple' => true, because the Entry instances do not exist before the Order.
This can be easily done by symfony using embedded form.
There are a lot to say about how to use it, so here are :
Fully example step by step of how to do it from entity creation to html implementation
The symfony cookbook : How to Embed a Collection of Forms
And symfony doc : How to Embed a Collection of Forms