Skip to content

Bug after PR 7600 #7721

Description

@dmitryuk

Hello
Related #7600

Describe the bug
After #7600 on my project I got a bug - createEntity called unexpectly while editing entries.

To Reproduce

class CrossSell
{
__construct(
        #[ORM\ManyToOne(targetEntity: CrossSellCampaign::class, inversedBy: 'crossSells')]
        #[ORM\JoinColumn(name: 'campaign_id', nullable: false)]
        private CrossSellCampaign $campaign,
)
{
$this->campaign->addCrossSell($this); // this needed to  consistent two-way relations (Symfony way)
}
}
class CrossSellCrudController extends AbstractCrudController
{
    public function createEntity(string $entityFqcn): CrossSell
    {
        $campaign = $this->em->getRepository(CrossSellCampaign::class)->findOneBy([]);
        assert($campaign instanceof CrossSellCampaign);
        $po = $this->em->getRepository(PriceOption::class)->findOneBy([]);
        assert($po instanceof PriceOption);

        $entity = new CrossSell(
            $campaign,
            $po,
            position: 0,
            placement: PlacementEnum::PROMO_BLOCK,
            actionType: ActionTypeEnum::ADD,
        );

        return $entity;
    }
}

After edit form opened a new random element is added to Campaign since createEntity is called unexpectedly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions