-
-
Notifications
You must be signed in to change notification settings - Fork 22
Many-to-many conjunctive (AND operator) queries #16
Comments
@Mickael-van-der-Beek wow, thanks for taking the time to come and show what you have done. If you'd be up for writing some tests, I think your version is very, very worthy of a PR. Your self-analysis of your code reminds me of myself 😆 Nothing in GQL is particularly pretty, it's all a bit experimental, but in my experience when trying to tackle something this fiddly the nice solutions really don't fall out until you have implementations for all the common use cases and have a full picture to work with. So yeah, please do submit a PR! |
Hi - I've opened a PR with a possible solution for this issue - after reviewing the changes that Mickael-van-der-Beek made to solve this issue - it didn't appear to support 1 of my tag filter scenarios . I have 2 tag filtering scenarios that my team uses in our custom Ghost template: filter="tag:sports+tag:football" and filter="tag:sports+tag:-football". I took the approach of creating sub-queries for each tag filter using knex to build the subquery. |
@ErisDS 2 years later, what is the current status of this one?
|
refs #10105, closes #10108, closes #9950, refs #9923, refs #9916, refs #9574, refs #6345, refs #6309, refs #6158, refs TryGhost/GQL#16 - removed GQL dependency - replaced GQL with our brand new NQL implementation - fixed all known filter limitations - GQL suffered from some underlying filter bugs, which NQL tried to fix - the bugs were mostly in how we query the database for relation filtering - the underlying problem was caused by a too simple implementation of querying the relations - mongo-knex has implemented a more robust and complex filtering mechanism for relations - replaced logic in our bookshelf filter plugin - we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex. NQL: https://github.com/NexesJS/NQL mongo-knex: https://github.com/NexesJS/mongo-knex
GQL was replaced by NQL. GQL is deprecated now. This bug was fixed in Ghost 2.8.0 with the help of NQL 0.2.1. |
This issue was already reported by @ErisDS on the main TryGhost/Ghost repository, issue reference:
TryGhost/Ghost#6158.
I actually really needed this feature to make my company's use-case work so I went ahead and implemented it in this branch of my fork:
And here's the diff compared to the current master branch:
https://github.com/TryGhost/GQL/compare/master...Mickael-van-der-Beek:many-to-many-conjunctive-queries?expand=1
As you can see the implementation is absolutely disgusting and that's also why I'm not trying to submit it as a PR. I just thought that maybe if someone worked on it in the future, they could use it a reference starting point.
A few thoughts about this implementation in no particular order:
having()
callWHERE ... IN ()
query is done on the column that is most usedprocessFilter()
(this one is not too important and can be fixed easily)But it the end it passes the test suite and seems to work well. For the use-case we had (which was a hack in itself using Ghost's tagging system), neither Ghost nor Ghost's API are public facing so that meant that this solution was sufficient for now.
After thinking about the problem at hand during the day, I don't think that it's possible to automatically generate the SQL query if the parent application doesn't hint at which column specifically will be used for the
WHERE ... IN ()
clause. Also, theHAVING
clause has a hard dependency on theGROUP
ed column(s) which means that for Ghost's use-case where query composition is done it will be hard to implement it in a non-hardcoded way if GQL stays in it's current form.The text was updated successfully, but these errors were encountered: