Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_ncontains doesn't work on o2m nested dataset #5996

Open
nordcart opened this issue Jun 2, 2021 · 12 comments · Fixed by #12082 or #13497
Open

_ncontains doesn't work on o2m nested dataset #5996

nordcart opened this issue Jun 2, 2021 · 12 comments · Fixed by #12082 or #13497
Labels

Comments

@nordcart
Copy link

nordcart commented Jun 2, 2021

Filter not working properly on nested items (on many to one or one to many)

  • Left column: ID
    id: 110

  • Right column: Jakso (info from another collection)
    id: 110 --> 1/2021, 2/2021, 3/2021

Trying to only show the ID:s which does not have 2/2021 anywhere in "Jakso" (screenshot).

In the screenshot ID:110 has got 2/2021, but is still shown.

image

@rijkvanzanten rijkvanzanten changed the title Filter not working properly on nested items _ncontains doesn't work on o2m nested dataset Jun 4, 2021
@rijkvanzanten rijkvanzanten added 🍰 Bug and removed App labels Jun 4, 2021
@rijkvanzanten
Copy link
Member

@martijnboland Sounds like we've found the limit of the subquery! Negation doesn't work how you would expect it.

Take the following minimal example:

authors & articles
articles.author -> authors.id

Fetch all authors that have an article where title IS NOT "Test"

The following SQL is used

SELECT
	"authors"."id",
	"authors"."name"
FROM
	"authors"
WHERE
	"authors"."id" in(
		SELECT
			"articles"."author" AS "author"
		FROM
			"articles"
		WHERE
			NOT "articles"."title" = 'Test'
	)
ORDER BY
	"authors"."id" ASC

However, this still fetches the top level author as soon as they have any other article that matches the search query 🤔

@martijnboland
Copy link
Contributor

martijnboland commented Jun 4, 2021

@rijkvanzanten ah crap, well maybe there is a possibility to generate a 'where exists' subquery instead of the 'where in'? Or wouldn't that make a difference? Still early morning here...

@rijkvanzanten
Copy link
Member

rijkvanzanten commented Jun 4, 2021

@martijnboland Sounds like a potential solution! Wondering how that affects the negation though 🤔 I believe you can do a "where not exists", but then we might have the opposite problem (where regular filters stop functioning)

@nordcart
Copy link
Author

Any news on this?

@nordcart
Copy link
Author

Has this been forgotten? There are probably more important bugs, but just asking :)

@rijkvanzanten
Copy link
Member

Certainly hasn't been forgotten. Unfortunately nobody else seemed to have ran into this issue, fixing it takes quite a lot of rethinking on how nested queries are constructed, and there are other more important bugs that took priority..

We recognize that this may be an important feature/fix, but we are a small open-source organization with a lot to triage and complete. As of now, the only way to get an accurate timeline or release date is to sponsor this task.

@nordcart
Copy link
Author

nordcart commented Dec 27, 2021

I don´t know what happend, I viewed this issue and it got automatically closed. Sorry.

@nordcart nordcart reopened this Dec 27, 2021
@joselcvarela
Copy link
Member

Hello,
I was trying to check if this got solved in the meantime but this seems a though one.
This will happen for all nested filters containing not operations.
Since we are recursively applying the filters, it will need a proper refactor in order to achieve the correct behaviour.

Instead of select ... where in (select .. where not ...), I think we will need select ... where not in (select .. where ...).
This requires that not operation needs to be converted into the affirmative ones(ie, neq to eq) and the not would be on root level.

@krazyjakee
Copy link
Contributor

krazyjakee commented Jan 14, 2022

Just to note that this also affects insights. For example, to find all items in a collection where an M2M field is empty is simply not possible.

I also can't think of reasonable workarounds...

  • Interact with Postgres directly and figuring out the queries. Reliant on having no breaking changes in the postgres structure.
  • Have a separate background worker that downloads all items in the collection through the API and then performs logic on the data to get the item IDs where the M2M field is an empty array. Not scalable.

Both of which are pretty ugly solutions. Any other suggestions welcome

@nordcart
Copy link
Author

nordcart commented Feb 1, 2022

I believe the Directus-team finds a solution.. no worries 😃. I think this feature would be really useful.

@nordcart
Copy link
Author

I don´t think #12082 solves this..did not work for me. #11737 should solve it.

jamescammarano pushed a commit that referenced this issue May 18, 2022
* feat: refactor apply-query & implements icontains

* feat: implements icontains in app

* New translations en-US.yaml

* tests: fix returns the filter operators for binary

* implement rest insensitive operators

* fix: proposal to fix #5996 (convert "in" into "exists")

* delete unused imports

* fix: prevent error when operator filter value is null

* fix: apply-query imports

* some tests

* fix: _nstarts_with not applied correctly

* tests: add some filter mathematical tests
@nickrum nickrum reopened this May 24, 2022
@rijkvanzanten
Copy link
Member

Linear: ENG-296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

6 participants