Skip to content

Using $or filters nullifies columns and produces an exception due to an invalid SQL query #111

@f-liva

Description

@f-liva

The filtering of a relationship, when included in an $or clause as shown in https://abbasudo.github.io/laravel-purity/advanced/param.html#changing-params-source, causes the following kind of error:

Query: /users/?filters[$or][profile][name][$contains]=John

SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'WHERE' (Connection: mariadb, SQL: select count(*) as aggregate from `users` where ((`` LIKE %John%)))

The raw query produced by Purity becomes:

select * from `users\` where \`\` LIKE '%John%'

Whereas the same query without the OR works correctly: /users/?filters[profile][name][$contains]=John

And produces a correct query:

select * from `users` where exists (select * from `profiles` where `users`.`id_profile` = `profiles`.`id` and `name` LIKE '%John%')

Note

The problem also occurs when using $or with conditions on NON-related columns.

Example: /users/?filters[$or][email][$contains]=@gmail&filters[$or][created_ate][$contains]=2025

Produces:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'WHERE' (Connection: mariadb, SQL: select count(* ) as aggregate from `users` where ((`` LIKE %@gmail@%) or (`` LIKE %2025%)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions