Skip to content

[DoctrineBridge][Form] EntityType updates related entity with enable_native_lazy_objects #61058

Open
@aleho

Description

@aleho

Symfony version(s) affected

7.3

Description

Having enable_native_lazy_objects = true and saving a form, even without changes, the related entity is updated with invalid data.

While saving, an SQL statement with UPDATE related_entity SET field1 = NULL, field2 = NULL WHERE id = [ID of related entity]; is executed.

How to reproduce

Two entities, one with a form, the other one as target of an EntityType:

// Product.php
    #[ORM\ManyToOne(inversedBy: 'products')]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?Vendor $vendor = null;


// Vendor.php
    /** @var Collection<array-key, Product> */
    #[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'vendor')]
    private Collection $products;


// ProductType.php
    ->add('vendor', EntityType::class, [
        'label'        => 'Vendor',
        'required'     => false,
        'class'        => Vendor::class,
        'choice_label' => static fn(Vendor $d) => $d->getName() . ' (' . $d->getCode() . ')',
    ])

Possible Solution

No response

Additional Context

Without native lazy objects:
without native lazy objects


Native lazy objects enabled:

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions