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

Fix(snippet): Error that occurred when there were no linked resources in the document #372

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from

Conversation

gitrequests
Copy link

When there are no linked resources in the document and the snippet getSelections is called, an error occurs due to an incorrectly composed query "sortby FIELD(...) in getSelections snippet (on line 94).

Screenshot from 2024-10-02 10-52-09
Error: Error 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') asc LIMIT 10' at line 1

Also, as far as I understand, it makes no sense to call the snippet getResources (pdoResources) if we already know that there are no linked resources. I suggest returning an empty result immediately if there are no linked resources in the document.

… in the document

When there are no linked resources in the document and the snippet getSelections is called, an error occurs due to an incorrectly composed query "sortby FIELD(...) in getSelections snippet.
Also, as far as I understand, it makes no sense to call the snippet getResources (pdoResources) if we already know that there are no linked resources. I suggest returning an empty result immediately if there are no linked resources in the document.
…tions

ability to use snippet parameters for empty results in getResources (pdoResources).
For example: &wrapIfEmpty
@gitrequests
Copy link
Author

Improved the snippet. In the previous version the snippets getResources and pdoResources did not run, so the parameters of these snippets for empty results did not work (for example: &wrapIfEmpty).

Now the snippet runs and the logic for empty results is processed directly from the snippets getResources or pdoResources.

I took the logic for constructing a query with an empty result from the MODx XPDOQuery class:
https://github.com/modxcms/xpdo/blob/ffa5d883ef44bd684db748a3e454071672913e48/src/xPDO/Om/xPDOQuery.php#L395C13-L395C33

@matdave matdave self-assigned this Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants