API Platform version(s) affected: 2.5.6
Description
I have an Doctrine Entity Class identified by an iso_code attribute :
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
/**
* @ApiResource(
* graphql={
* "item_query",
* "collection_query"
* }
* )
*
* @ORM\Entity(repositoryClass="App\Repository\LanguageRepository")
* @ORM\HasLifecycleCallbacks
*/
class Language extends BaseEntity
{
/**
* @var string
* @ApiProperty(identifier=true)
*
* @ORM\Id()
* @ORM\Column(type="string", length=2, unique=true)
*/
private $iso_code;
public function getId(): string
{
return $this->iso_code;
}
public function getIsoCode(): string
{
return $this->iso_code;
}
}
I though the @ApiProperty(identifier=true) annotation would have done the trick but it doesn't.
I also tried to add a getId() method but without success.
When I try to access a list through a GET requests /api/v2/languages?pages=1, I got "No identifiers defined for resource of type \"App\\Entity\\Language\"" error.
When I try to access an item through a GET requests /api/v2/languages/en, I got Invalid identifier value or configuration
I looked for 2 hours now in the documentation and internet but can't find why.
did you find out ?
@ADcreatif Nope.
The only way to make this work was to rename $iso_code to $id.
Hi I faced similar problem today, I fixed it by making the id key public
here is my working example :
class Book
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
* @ApiProperty(identifier=true)
* @ORM\Id
*/
public $book_id;
Most helpful comment
Hi I faced similar problem today, I fixed it by making the id key public
here is my working example :