I have a relationship from Assembly to ComponentSlot. It is a OneToMany relationship.
// Assembly
/**
* @ORM\OneToMany(targetEntity="ComponentSlot", mappedBy="assembly", cascade={"persist"})
* @Assert\Valid
*/
protected $componentSlots;
// ComponentSlot
/**
* @ORM\ManyToOne(targetEntity="Assembly", inversedBy="componentSlots")
*/
protected $assembly;
The schema this has generated in the database is absolutely fine. Correct columns, correct indices and relations.
The Symfony2 form AssemblyType has a collection of ComponentSlotType. I am able to add multiple ComponentSlot children. On persisting, the Assembly and ComponentSlot children are all saved perfectly well, except that assembly_id is NULL in the component slot table.
I have copied the setup I had on a previous project that saved the relationships just fine, I am completely stumped. The cascade persist is set on the componentSlots fields of Assembly and my past experience with OneToMany is that I do not have to do anything special here, it should be taken care of.
Any pointers would be appreciated :)
Check your previous setup. I suspect you had something like:
// Assembly
public function addComponentSlot($componentSlot)
{
$this->componentSlots[] = $componentSlot;
$componentSlot->setAssembly($this); // Probably left this out when you copied?
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With