foundry: Entity cascading unexpected behavior
In the case we have 3 entities linked together likes:
class A
{
/**
* @ORM\OneToMany(targetEntity=B::class, mappedBy="a", cascade={"persist"})
*/
private Collection $bs;
private ?string $reference = null;
public function __construct() {
$this->bs = new ArrayCollection();
}
}
class B
{
/**
* @ORM\ManyToOne(targetEntity=A::class, inversedBy="bs")
* @ORM\JoinColumn(nullable=false)
*/
private ?A $a = null;
/**
* @ORM\ManyToOne(targetEntity=C::class, inversedBy="bs", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private ?C $c = null;
private ?string $reference = null;
}
class C
{
/**
* @ORM\OneToMany(targetEntity=B::class, mappedBy="c")
*/
private Collection $bs;
private ?string $reference = null;
public function __construct() {
$this->bs = new ArrayCollection();
}
}
There is listener on A and C to generate tha A, B and C references. The A listener loop over the collection of B. It works well in the application, but when I want to create a fixture for A… It totally explode, when Foundry call the persist, there is no B inside the collection (in A class). But to generate the A reference I need the first B class of the collection and the linked C class.
Someone know how we can do this ? Actually I’ve something similar to:
AFactory::createOne();
Internally:
- AFactory call BFactory::new()->many(3);
- BFactory call CFactory::new();
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (20 by maintainers)
I check it tomorrow, and say you what I find. Thanks a lot for your help 🙏