question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SearchFilter on relation / nested attribute

See original GitHub issue

I’m trying to filter on a relation property, and following the docs I added an annotation on the property:

    /**
     * @Groups({"campaign:get",  "campaign:post"})
     *
     * @ApiFilter(SearchFilter::class, properties={"product.name": "ipartial"})
     *
     * @ORM\ManyToOne(targetEntity="App\Entity\product", inversedBy="campaigns")
     * @ORM\JoinColumn(nullable=false)
     */
    private $product;

Then, acessing the resource at {{url}}/api/campaigns/?product.name=CAM return all resources, including those that do not match the search.

Am I missing anything else in order to enable the filter?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Lobosquecommented, Sep 25, 2018

@soyuka the problem was appending a slash and getting a 301 redirect:

{{url}}/api/campaigns/?product.name=art ---> do not work
{{url}}/api/campaigns?product.name=art  ----> works

I only figured this out thanks to your tip about using the Hydra serialization. It looks like with the redirect, the dot get translated to an underscore somewhere:

    "hydra:view": {
        "@id": "/api/campaigns?product_name=art",
        "@type": "hydra:PartialCollectionView"
    },

While this is definitely a bug, this is probably not related to Api Platform.

0reactions
teohhanhuicommented, Dec 19, 2018

Indeed, it’s how PHP processes the query parameters. There’s nothing we could do about it if the original information is lost.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Api platform aliasing filters for nested resources - Stack Overflow
I'm currently using API Platform and its default SearchFilter and it works as intended. However, filtering on ...
Read more >
Filter on (nested) relationship attribute? - JSON API
Another I'm wondering is how to filter on nested relationships. Image the author has a nationality relationship with a alpha2-code attribute ...
Read more >
How to Filter Results on Deeply Nested fields in Strapi
The ?filters parameter offers the ability to filter results. [authors] is a relation field in the Book collection type.
Read more >
Working with Advanced Search Filter Options - Reltio
HCP has nested attributes identifiers, and a search returns 5 HCP. Out of these 5 HCP, only one has two identifiers. If the...
Read more >
Active Directory user filter does not search nested groups
Cause. Crowd uses basic LDAP syntax rules for searching. By default, any searches with memberOf will only check direct attributes, so AD will ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found