-1

When I have a document property using a dbRef - relation like this:

/**
 * @MongoDB\ReferenceOne (
 *     discriminatorMap={
 *       "post"=Post::class
 *     },
 *     defaultDiscriminatorValue="post",
 *     storeAs="dbRef",
 *     inversedBy="references",
 *     cascade={"persist"}
 * )
 */
protected DocumentInterface $target;

How can I apply the built-in SearchFilter from Api_Platform to return all items with a matching dbRef and what would the adequate Request look like?

Timor Kodal
  • 324
  • 3
  • 7
  • I thought I might be able to filter available items by querying by IRI, but when I specify the filter with #[ApiFilter(SearchFilter::class, properties: [ 'target' => 'exact' ])] and add &target=, I retrieve an error message: ApiPlatform\\Core\\Bridge\\Doctrine\\MongoDbOdm\\Filter\\SearchFilter::getClassMetadata(): Argument #1 ($resourceClass) must be of type string, null given – Timor Kodal Jan 31 '22 at 14:04

1 Answers1

0

I have now implemented a workaround myself by creating a custom dbRef-Filter to add a filter for existing references to the AggregationBuilder.

$aggregationBuilder->match()->field($property)->references($document);
Timor Kodal
  • 324
  • 3
  • 7