Skip to content

Conversation

@gitrequests
Copy link
Contributor

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
Contributor 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
@theboxer theboxer merged commit c17a111 into modxcms:3.x Nov 14, 2024
theboxer added a commit that referenced this pull request Nov 14, 2024
@theboxer
Copy link
Member

@gitrequests thank you for the PR! Also ported to the 2.x branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants