statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.11k stars 538 forks source link

Quering against a boolean entry value does not give a result. #11094

Closed freshface closed 1 week ago

freshface commented 2 weeks ago

Bug description

Quering against a boolean entry value does not give a result.

Yaml data:

---
id: a03a6b20-595a-4019-9463-b99923908164
blueprint: dictionary
title: 'Blijf kalm. '
title_fr: 'Restez calme.'
title_en: 'Keep calm.'
voor_kappers: true
voor_schoonheidssector: true
themas: sos-zinnen
type: zin
audio_nl: blijf-kalm_nl.mp3
audio_fr: restez-calme_fr.mp3
audio_en: keep-calm_en.mp3
---

Query:

$entries = Entry::query()->where('collection', 'dictionary')->where('voor_kappers ', '=', true);
$entries = $entries->get();

Does not give any results. The debugbase says the query is like this (it casts a boolean to 1)

select * from entries where collection in ('dictionary') and voor_kappers = '1'

How to reproduce

See above

Logs

No response

Environment

Environment
Application Name: Febelhair
Laravel Version: 10.48.22
PHP Version: 8.3.8
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: febelhair.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Locales
Installed
LaravelLang\Actions\Plugin: 1.8.5
LaravelLang\Attributes\Plugin: 2.11.1
LaravelLang\HttpStatuses\Plugin: 3.8.5
LaravelLang\Lang\Plugin: 13.12.0
Locales Version: 1.9.0
Protected
Publisher Version: 15.0.2

Livewire
Livewire: v3.5.11

Statamic
Addons: 11
Sites: 3 (English, Dutch, French)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.37.0 PRO

Statamic Addons
aerni/social-links: 3.2.0
aryehraber/statamic-captcha: 1.13.0
figure8/launch: dev-main
jacksleight/statamic-bard-texstyle: 3.3.0
jonassiewertsen/statamic-livewire: 3.8.1
ryanmitchell/statamic-translation-manager: 2.0.0
spatie/statamic-responsive-images: 5.1.0
studio1902/statamic-peak-browser-appearance: 3.5.0
studio1902/statamic-peak-seo: 8.16.0
studio1902/statamic-peak-tools: 6.3.3
trendyminds/statamic-palette: 1.2.1

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

duncanmcclean commented 2 weeks ago

What's the fieldtype of the voor_kappers field? A toggle?

freshface commented 2 weeks ago

Yes

duncanmcclean commented 2 weeks ago

If you remove ->where('collection', 'dictionary') from the query, do you get any results?

freshface commented 2 weeks ago

Same issue, no results. I also tried it on another value by adding ->where('audio_nl ', '=', 'blijf-kalm_nl.mp3')

To search for that value in an entry, but same issue.

---
id: a03a6b20-595a-4019-9463-b99923908164
blueprint: dictionary
title: 'Blijf kalm. '
title_fr: 'Restez calme.'
title_en: 'Keep calm.'
voor_kappers: true
voor_schoonheidssector: true
themas: sos-zinnen
type: zin
audio_nl: blijf-kalm_nl.mp3
audio_fr: restez-calme_fr.mp3
audio_en: keep-calm_en.mp3
---
freshface commented 2 weeks ago

This works: ->where('title_en', '=', 'Keep calm.') I think this is because the value in the yaml is also a string and audio_nl: blijf-kalm_nl.mp3 has no quotes (same as for voor_kappers: true ?)

duncanmcclean commented 2 weeks ago

Those should be fine without quotes.

I'm unable to replicate these issues locally - are you able to reproduce them on a fresh site?

freshface commented 1 week ago

I found my issue ->where('audio_nl ', '=', 'blijf-kalm_nl.mp3') there was a space .... in my query 'audio_nl ', the the space after _nl

duncanmcclean commented 1 week ago

Ah I see, that would do it!

Glad you managed to figure it out.

freshface commented 1 week ago

Haha yes, took my some time... (stupid space :)