I am currently working on programming a website using Symfony version 6.2 and API Platform in addition to MongoDB (version v6.0.3) in the database.
I try to use the Subresources and I followed the official documentation of the API Platform: https://api-platform.com/docs/core/subresources/
I tried to use exactly what is written on the documentation (this the code):
#[ApiResource(
uriTemplate: '/companies/{companyId}/employees',
operations: [ new GetCollection() ]
uriVariables: [
'companyId' => new Link(toProperty: 'company', fromClass: Company::class),
]
)]
class Employee
{
#[MongoDB\Id()]
private string $id;
#[MongoDB\Field(type: Type::STRING)]
private string $name;
#[MongoDB\ReferenceOne(targetDocument: Company::class, inversedBy: "employees")]
private ?Company $company;
public function getId()
{
return $this->id;
}
}
and for the Company class:
#[ApiResource]
class Company
{
#[MongoDB\Id()]
public string $id;
#[MongoDB\Field(type: Type::STRING)]
public string $name;
#[MongoDB\ReferenceMany(targetDocument: Employee::class, mappedBy: "company")]
/** @var Employee[] */
#[Link(toProperty: 'company')]
public $employees = [];
}
but while using the Postman to get the result from /companies/{companyId}/employees
, this error message appears:
"Cannot use reference 'company' in class 'App\\Document\\Company' for lookup or graphLookup: dbRef references are not supported."
Is there any solution for that?