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

Querying lightswitch returns Null #5866

Closed
ghost opened this issue Mar 31, 2020 · 9 comments
Closed

Querying lightswitch returns Null #5866

ghost opened this issue Mar 31, 2020 · 9 comments

Comments

@ghost
Copy link

ghost commented Mar 31, 2020

Description

After adding a lightswitch field the following query won't work. It always returns null.

craft.entries
        .section('articles, events, projects, stories')
        .with(['mainImage'])
        .relatedTo(category)
        .showInGrid(true)
        .orderBy('stickyPost desc, postDate desc')
        .limit(9)

I tried showInGrid(1), showInGrid('1'), showInGrid('not 1') etc etc

When I remove the 'showInGrid' parameter and loop through all entries. The showInGrid parameter is returning correcly. And returns 1 or null.

Any clue?

Additional info

  • Craft version: 3.4.11
  • PHP version: 7.1.12
  • Database driver & version:
@brandonkelly
Copy link
Member

Do you have any entries where the showInGrid Lightswitch field is actually enabled?

@ghost
Copy link
Author

ghost commented Mar 31, 2020

Yes, I enabled a few entries (different sections: articles, events, projects, stories) with showInGrid Lightswitch field settings enabled.

Update
All entries showInGrid field switched to status on. I have checked the DB, all set to value 1. Still no luck.

@brandonkelly
Copy link
Member

It’s working fine on my end. You sure the field handle is spelled correctly in the template and the field settings? (It’s case-sensitive, too.)

@ghost
Copy link
Author

ghost commented Mar 31, 2020

I have created a screencapture. I guess that's the easiest way. Maybe you can help me out? :-)

https://www.dropbox.com/s/iliyveg3ju1ygd5/screencapture.mp4?dl=0

@brandonkelly
Copy link
Member

Are you using MySQL or Postgres?

@ghost
Copy link
Author

ghost commented Mar 31, 2020

I am using a MySQL DB

@brandonkelly
Copy link
Member

I’m a little stumped. Can you please email [email protected] with your composer.json and composer.lock files, as well as a database backup?

@brandonkelly
Copy link
Member

Issue here ended up being that the lightswitch values were in fact not set to 1 in the DB – they were still null – so their values in the templates only looked like the field was enabled, per the field’s default value (see #2404).

As of the next release, Lightswitch field params will now include null results so long as the param value matches the default value. So if you pass .myLightswitchField(true) and the default value is enabled, then any null DB values will be included in the results.

@brandonkelly
Copy link
Member

Craft 3.4.13 is out now with this fix.

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

No branches or pull requests

1 participant