core icon indicating copy to clipboard operation
core copied to clipboard

Fetch EAGER ManyToOne nullable relation cannot be nulled during PUT or PATCH operation

Open ambroisemaupate opened this issue 1 year ago • 3 comments

API Platform version(s) affected: 3.2.16

Description

Entities with ORM\ManyToOne(fetch: 'EAGER') nullable relation can be setted during a PUT or PATCH with an IRI, but cannot be nulled.

If I remove fetch: 'EAGER', I can set relation to null.

How to reproduce

With EAGER fetch

#[ORM\ManyToOne(targetEntity: File::class, fetch: 'EAGER')]
#[ORM\JoinColumn(name:'image_id', nullable: true, onDelete: 'SET NULL')]
#[Groups(['block:read', 'block:write', 'webPage:single:read'])]
#[ApiProperty(description: 'File IRI reference', example: '/api/files/1ee8859e-d2fd-6bda-ae37-d9341637fbc1')]
private ?File $image = null;

image

When I inspect request in Symfony Profiler: previous_data contains an image but data too !

image

Without EAGER fetch

#[ORM\ManyToOne(targetEntity: File::class)]
#[ORM\JoinColumn(name: 'image_id', nullable: true, onDelete: 'SET NULL')]
#[Groups(['content:read', 'content:write'])]
#[ApiProperty(description: 'File IRI reference', example: '/api/files/1ee8859e-d2fd-6bda-ae37-d9341637fbc1')]
private ?File $image = null;

image

When I inspect request in Symfony Profiler: previous_data contains an image then data has null image

image

ambroisemaupate avatar Mar 14 '24 16:03 ambroisemaupate

can you provide a reproducer ?

soyuka avatar Mar 15 '24 11:03 soyuka

can you provide a reproducer ?

I'll make that. Male or female ? For the reproducer :rofl:

ambroisemaupate avatar Mar 15 '24 15:03 ambroisemaupate

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 14 '24 23:05 stale[bot]