Replies: 1 comment 2 replies
-
Have you try to implement a custom filter? (see documentation) For a Doctrine filter, by implementing the method filterProperty, you can access the Resulting in something like this (untested pseudo code): protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, Operation $operation = null, array $context = []): void
{
// ...
$alias = $queryBuilder->getRootAliases()[0];
$inventoryAlias = $queryNameGenerator->generateJoinAlias('inventoryProduct');
$queryBuilder->leftJoin("$alias.inventoryProducts", $inventoryAlias);
$queryBuilder->andWhere("$inventoryAlias.isArchived = :isArchived");
$queryBuilder->setParameter('isArchived', false);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question:
I'm trying to retrieve products that are associated with at least one non-archived inventory using API Platform Boolean/Numeric Filter. Currently, my query looks like this: /api/products?inventoryProducts.isArchived=1. However, I would like the filter to return the products and also affect the
product.inventoryProducts
relationship. As it stands, the filter returns all associated inventories. Except that I would like the relationship to be filtered.Here's my Product class:
And this is my InventoryProduct class:
Any help or suggestions would be greatly appreciated. Cheers!"
Beta Was this translation helpful? Give feedback.
All reactions