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.

Filter not working with embedded properties (multiple levels)

See original GitHub issue

I dont know if this relates to https://github.com/api-platform/api-platform/issues/277 but I have a issue with filtering by embedded properties. For example, I have to following entity structure:

  • User has Profile
  • Profile has Address
  • Address has postalCode (string)

So when I call

/api/users?profile.address.postalCode=88

with the filter configuration

filter.search_user:
        parent:    'api_platform.doctrine.orm.search_filter'
        arguments: [ { profile.firstName: 'partial', profile.lastName: 'partial', profile.address.postalCode: 'starts' } ]
        tags:      [ { name: 'api_platform.filter', id: 'filter.search_user' } ]

I would expect a response that only contains users with a postal code starting with 88. But all users are returned since the filter is not applied at all.

The same issue occurs when I call

/api/users?profile.firstName=Thomas

what should return only users with Thomas in their firstName but all users are returned. I digged a lot in the issues and found https://github.com/api-platform/core/pull/242 and https://github.com/api-platform/core/issues/83.

So is this already a feature and/or am I facing a bug?

EDIT: Thought that only occurs with embedded entities deeper that one level. But it seems its not possible to filter by embedded entity properties at all.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
blaues0ckecommented, May 15, 2017

Thanks. Can confirm that https://github.com/api-platform/core/pull/984 works like a charm. Also I accidentally used starts instead of start.

1reaction
soyukacommented, May 9, 2017

@Simperfit should work with as many levels as we need:

filters

Extract of filters services:

    product_referencing.filter.date:
        parent: 'api_platform.doctrine.orm.date_filter'
        arguments: [ { 'fromDate': 'include_null_after', 'thruDate': 'include_null_after' } ]
        tags: [ {name: 'api_platform.filter', id: 'product_referencing.filter.date' }]

    product_referencing.filter.enabled:
        parent: 'api_platform.doctrine.orm.boolean_filter'
        arguments: [ { 'enabled': ~, 'product.productToPackaging.isDefault': ~, 'product.productInternalOrganization.referencingStatus.isBlocking': ~} ]
        tags: [ {name: 'api_platform.filter', id: 'product_referencing.filter.enabled' }]

    product_referencing.filter.product:
        parent: 'api_platform.doctrine.orm.search_filter'
        arguments: [ { 'product': 'exact', 'product.category.id': 'exact', 'product.priceDefinitionFamily.id': 'exact', 'product.code': 'exact', 'product.productInternalOrganization.internalOrganization': 'exact' } ]
        tags: [ {name: 'api_platform.filter', id: 'product_referencing.filter.product' }]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter through multiple levels nested array - Stack Overflow
As you can see it consists of elements with 2 properties: name and children . This is simple list but it can be...
Read more >
Nested field type | Elasticsearch Guide [8.5] | Elastic
The following parameters are accepted by nested fields: dynamic: (Optional, string) Whether or not new properties should be added dynamically to an existing ......
Read more >
How to filter nested objects in JavaScript ? - GeeksforGeeks
The filter() method creates a new array with all elements that pass the test implemented by the provided function.
Read more >
Views, filters & sorts – Notion Help Center
In your sidebar, views show up as nested items inside any full-page database. ... Filters: add criteria based on property values to show...
Read more >
filter - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
When a filter property has two or more functions, its results are different from the same functions applied separately using multiple filter ......
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