core icon indicating copy to clipboard operation
core copied to clipboard

fix(doctrine): fix error when identifier is not 'id'

Open GaryPEGEOT opened this issue 1 year ago • 2 comments

Q A
Branch? 3.2

When your entity identifier is not named id, your uriVariables (if not customized) will contains something like ["id" =>"THE_CODE"], but Doctine will throw if you send an array as it expect something like ["nameOfIdentifer" =>"THE_CODE"]

By using the identifier directly, we let doctrine figure out the rest

GaryPEGEOT avatar Feb 01 '24 09:02 GaryPEGEOT

There's an array_key_exists how do you go through there without any id?

soyuka avatar Feb 01 '24 14:02 soyuka

@soyuka in my case, the class doesn't have any id property (identifier is named sku). I've added #[ApiProperty(identifier: true)] on top of my property, but for some reason identifiers contains sku and an imaginary id prop. So I did:

 new Get(
            uriVariables: ['id' => new Link('id', fromClass: MyClass::class, identifiers: ['sku'])],
           // ...
        ),

GaryPEGEOT avatar Feb 02 '24 10:02 GaryPEGEOT

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 Apr 09 '24 21:04 stale[bot]