API Platform version(s) affected: 3.3.11
Description
An error occurs when attempting to retrieve a sub-resource (Employee) via its IRI, using the fetch_data option set to false. The error Doctrine\ORM\Exception\UnrecognizedIdentifierFields is raised, indicating that the required identifier fields ('companyId') are not present on the App\Entity\Employee class. This issue directly affects the use of the SearchFilter when an IRI is sent to it.
How to reproduce
- Use the Employee and Company entities from the API Platform documentation (https://api-platform.com/docs/core/subresources/#company-employees).
- Execute the provided PHP code to create instances of
Company and Employee, persist them, and then retrieve an instance of Employee by its IRI with fetch_data set to false.
$entityManager = ... ;
$iriConverter = ... ;
$company = new Company();
$company->name = 'test';
$entityManager->persist($company);
for ($i = 0; $i < 3; ++$i) {
$employee = new Employee();
$employee->name = "Employee numer $i";
$employee->company = $company;
$company->employees[] = $employee;
$entityManager->persist($employee);
}
$entityManager->flush();
$employee = $company->employees[1];
dump($employee->getId());
$employeeIri = $iriConverter->getIriFromResource($employee);
dump($employeeIri);
$employee = $iriConverter->getResourceFromIri($employeeIri, ['fetch_data' => false]); // Error here: Doctrine\ORM\Exception\UnrecognizedIdentifierFields: Unrecognized identifier fields: "companyId" are not present on class "App\Entity\Employee"
dump($employee->getId());
Additional Context
The fetch_data false option is intended to minimize data loading when retrieving entities via an IRI, typically with the SearchFilter. However, the indicated error suggests an issue in managing the identifiers of the Employee entity when accessed in this manner, leading to a malfunction in the sub-resources mechanism.
API Platform version(s) affected: 3.3.11
Description
An error occurs when attempting to retrieve a sub-resource (Employee) via its IRI, using the
fetch_dataoption set to false. The errorDoctrine\ORM\Exception\UnrecognizedIdentifierFieldsis raised, indicating that the required identifier fields ('companyId') are not present on theApp\Entity\Employeeclass. This issue directly affects the use of theSearchFilterwhen an IRI is sent to it.How to reproduce
CompanyandEmployee, persist them, and then retrieve an instance ofEmployeeby its IRI withfetch_dataset to false.Additional Context
The
fetch_datafalse option is intended to minimize data loading when retrieving entities via an IRI, typically with theSearchFilter. However, the indicated error suggests an issue in managing the identifiers of theEmployeeentity when accessed in this manner, leading to a malfunction in the sub-resources mechanism.