How to use SearchFilter using a dbRef with Api_Platform?

48 Views Asked by At

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?

1

There are 1 best solutions below

0
Timor Kodal On

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);