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

Searching for not empty grid field in {exp:channel:entries} tag is not possible #2670

Closed
shbchk opened this issue Dec 23, 2022 · 4 comments · Fixed by #3263
Closed

Searching for not empty grid field in {exp:channel:entries} tag is not possible #2670

shbchk opened this issue Dec 23, 2022 · 4 comments · Fixed by #3263
Labels
Bug: Invalid Issue is either not a bug, or external in nature. under review An EE team member is reviewing this issue

Comments

@shbchk
Copy link

shbchk commented Dec 23, 2022

EE 7.2.5
PHP 7.4.21

I have two entries:
Entry id 2: Entry without content in a grid field
Entry id 1: Entry with content in a grid field

What I need
Show only entries that have rows in a grid field.

What I tried to do

Try 1

{exp:channel:entries channel="test" search:grid_field="not IS_EMPTY" limit="1"}
{if no_results}
<h1>Nothing</h1>
{/if}

<h1>{title}</h1>
{/exp:channel:entries}

Output:

Nothing

Try 2

{exp:channel:entries channel="test" search:grid_field:total_rows=">=1" limit="1"}
{if no_results}
<h1>Nothing</h1>
{/if}

<h1>{title}</h1>
{/exp:channel:entries}

Output:

Entry without content in a grid field
@shbchk shbchk changed the title Searching for not empty grid field in entries tag is not possible Searching for not empty grid field in {exp:channel:entries} tag is not possible Dec 23, 2022
@intoeetive
Copy link
Contributor

@TomJaeger @bryannielsen @matthewjohns0n let's discuss this after new year.
Without deep dive, I think this represents an old issue where if you save Grid without rows, it could be saved as empty array. Which is not qualified for IS_EMPTY check.
I think we could either:

  • convert empty arrays to NULL when saving Grid
  • make IS_EMPTY check treat empty arrays same as NULL
  • do something specifically for Grids???

@intoeetive
Copy link
Contributor

After discussion, we concluded that:
a) this needs to be fixed
b) we should look into approach that does not modify the saved data, or how data are saved

@intoeetive intoeetive added the Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. label Feb 1, 2023
@intoeetive
Copy link
Contributor

So I had a deeper dive today.

Using search parameter against Grid fields (including IS_EMPTY check) works fine if the field is set as searchable.
To me, this makes sense, because in case of complex fields like Grid we don't stack join over join to perform search, we merely check the main field_id_X column. Which contains searchable data, which is empty if the field is not searchable.

We actually have this documented: https://docs.expressionengine.com/latest/channels/entries.html#searchfield_name

But I wonder if it makes sense to add a message to template debugger when people try doing something like that (search relationship field, or search non-searchable grid) - might save them some time

@intoeetive intoeetive added Bug: Invalid Issue is either not a bug, or external in nature. under review An EE team member is reviewing this issue and removed Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. labels Apr 11, 2023
@robinsowell
Copy link
Contributor

OH, I love adding it to the template debugger! And agree, logic makes sense as far as the behavior- that's what I'd expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Invalid Issue is either not a bug, or external in nature. under review An EE team member is reviewing this issue
Projects
None yet
3 participants