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.
You can use
CollectionType::classto embed another form. Create aEntryTypeform and add it to yourOrderTypeform with aCollectionTypefield. Add aallow_addproperty and check the docs to find how to display the Form.If you want to persist/flush all entities, you have to add a `cascade={'persist'} to your relation.