Skip to content

Filtering on multiple fields on one model relationship #116

@OwenOwlCentre

Description

@OwenOwlCentre

Hey, I am having an issue filtering on multiple fields on the same relationship.

I have created a pull request adding a test to demonstrate this: #115.

it attempts to filter products that have books with name = book and page count = 100, using the following url:

/products?filters[book][name][$eq]=book&filters[book][page_count][$eq]=100

If you look at the sql generated:

SELECT * FROM "products" WHERE EXISTS ( SELECT * FROM "books" WHERE "products"."id" = "books"."product_id" AND "name" = ? ) AND EXISTS ( SELECT * FROM "books" WHERE "products"."id" = "books"."product_id" AND "page_count" = ? )

Because the EXISTS clauses are added separately for the same relationship, it returns products where there exists one book matching the first condition and there exists a (potentially different) book matching the second condition, rather than requiring a single book that matches both conditions simultaneously.

is this intended/am I creating the query correctly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions