API Platform version(s) affected: x.y.z
3.1.12
Description
I have api resource entity that is only one in the database and it has ID 1. I have set up the entity like this
<?phpnamespaceApp\Entity;
useApiPlatform\Metadata\ApiResource;
useApiPlatform\Metadata\Get;
useApiPlatform\Metadata\Patch;
useApp\Repository\SettingsRepository;
useDoctrine\DBAL\Types\Types;
useDoctrine\ORM\MappingasORM;
useSymfony\Component\Serializer\Annotation\Groups;
#[ApiResource(
operations: [
newGet(
uriTemplate: "/settings.{_format}",
),
newPatch(
uriTemplate: "/settings.{_format}",
),
],
normalizationContext: [
"skip_null_values" => false,
"groups" => ["settings:read"],
],
denormalizationContext: [
"skip_null_values" => false,
"groups" => ["settings:write"],
],
)]
#[ORM\Entity(repositoryClass: SettingsRepository::class)]
class Settings
{
#[ORM\Id]
#[ORM\GeneratedValue("NONE")]
#[ORM\Column(type: Types::INTEGER)]
privateint$id = 1;
#[Groups(["settings:read", "settings:write"])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string$text = null;
publicfunctiongetId(): int
{
return$this->id;
}
publicfunctiongetText(): ?string
{
return$this->text;
}
publicfunctionsetText(?string$text): self
{
$this->text = $text;
return$this;
}
}To my surprise I can GET /api/settings the entity just fine. But the PATCH /api/settings throws errors because it's trying to insert new entity and failing because there is already entity with ID 1.
How to reproduce
Use entity from description above, try PATCHing the entity by sending 'text' field
Possible Solution
Additional Context
API Platform version(s) affected: x.y.z
3.1.12
Description
I have api resource entity that is only one in the database and it has ID 1. I have set up the entity like this
To my surprise I can GET /api/settings the entity just fine. But the PATCH /api/settings throws errors because it's trying to insert new entity and failing because there is already entity with ID 1.
How to reproduce
Use entity from description above, try PATCHing the entity by sending 'text' field
Possible Solution
Additional Context