Skip to content

joinFields with myfield='' causes "Unknown column" error #2067

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

Open
tuomassalo opened this issue Apr 23, 2025 · 1 comment
Open

joinFields with myfield='' causes "Unknown column" error #2067

tuomassalo opened this issue Apr 23, 2025 · 1 comment

Comments

@tuomassalo
Copy link

ProcessWire forms an invalid SELECT clause if a field is in joinFields AND is also in a condition that demands it to be empty.

Both of these:

$pages->find("template=basic-page, title='', field=title");

$pages->find("template=basic-page,title=''", ["joinFields" => ["title"]]);

result in:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_title.data' in 'field list';

The invalid select clause looks like this: (slightly formatted for clarity)

SELECT
    (
        SELECT COUNT(*) FROM pages AS children
        WHERE children.parent_id = pages.id
    ) AS numChildren,
    field_title.data AS title__data,
    pages.*,
    UNIX_TIMESTAMP (pages.created) AS created,
    UNIX_TIMESTAMP (pages.modified) AS modified,
    UNIX_TIMESTAMP (pages.published) AS published,
    pages_sortfields.sortfield AS sortfield
FROM
    pages
    LEFT JOIN pages_sortfields ON pages_sortfields.pages_id = pages.id
    LEFT JOIN field_title AS field_title__blank1 ON field_title__blank1.pages_id = pages.id
WHERE
    (pages.templates_id = 29)
    AND (pages.status < 1024)
    AND (
        field_title__blank1.data IS NULL
        OR (field_title__blank1.data = '')
    )
GROUP BY
    pages.id

What I expected?

I expected the find call to succeed and the joined field be available without further queries.

Notes

In the example above, title was used. But it seems any field will result in the same error.

ryancramerdesign added a commit to processwire/processwire that referenced this issue May 2, 2025
@ryancramerdesign
Copy link
Member

@tuomassalo Thanks, I've pushed a fix for this issue.

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

No branches or pull requests

2 participants