<p>I believe this should work (not tested):</p>

<pre><code>$criteria-&gt;setAttribute('denied', 'not 1');
</code></pre>

<p>As when <a href="https://craftcms.stackexchange.com/questions/237/how-do-i-check-if-a-lightswitch-field-is-false/239#239">using the <code>ElementCriteriaModel</code> in Twig</a>, you can't directly check for "falsey" values.</p>

CC BY-SA 3.0
2017-05-08T17:53:44.523Z
Yes this is the correct way to test for a false boolean in the database! Thanks!
Rick Kukiela
CC BY-SA 3.0
2017-05-08T17:55:00.600Z
I actually ended up using `$criteria->denied = 'not 1';`
Rick Kukiela
CC BY-SA 3.0
2017-05-08T18:05:25.767Z
Sure, that's an alternative. It's just calling the `setAttribute` method behind the scenes anyway.
Stephen Lewis
CC BY-SA 3.0
2017-05-04T21:07:41.353Z
2017-05-04T21:20:34.073Z
2017-05-04T21:20:34.073Z
Stephen Lewis
<p>I have a custom content table for an elementType. I have a few fields set up in my <code>Record</code> as boolean. The two fields are <code>approved</code> and <code>denied</code> I have to search the database where both fields are set to zero/false.</p>

<p>I can only get the values to show up in <code>$query-&gt;params</code> inside my <code>modifyElementsQuery()</code> method when I set <code>$criteria-&gt;approved/denied</code> to (string)"1". Setting these to true, false, or (string)"0" cause them to not show up in the <code>$query-&gt;params</code> list.</p>

<p>How do I work with a boolean field in this manner? I need <code>Where denied = '0'</code> to show up in the query when i set <code>$criteria-&gt;denied = false</code></p>

<plugin-development><database><elementcriteriamodel><elementtype>
getCriteria not working as expected with boolean field types
# getCriteria not working as expected with boolean field types

(Asked by: username_0 on 2017-05-04)

I have a custom content table for an elementType. I have a few fields set up in my `Record` as boolean. The two fields are `approved` and `denied` I have to search the database where both fields are set to zero/false.

I can only get the values to show up in `$query->params` inside my `modifyElementsQuery()` method when I set `$criteria->approved/denied` to (string)"1". Setting these to true, false, or (string)"0" cause them to not show up in the `$query->params` list.

How do I work with a boolean field in this manner? I need `Where denied = '0'` to show up in the query when i set `$criteria->denied = false`

**Tags:** plugin-development, database, elementcriteriamodel, elementtype

---

## 1 answers

### Answer by username_1 on 2017-05-04. Score: 1 | Accepted answer

I believe this should work (not tested):
$criteria->setAttribute('denied', 'not 1');

As when using the ElementCriteriaModel in Twig, you can't directly check for "falsey" values.

> **Comments:**
> **username_0**: Yes this is the correct way to test for a false boolean in the database! Thanks!  
> **username_0**: I actually ended up using `$criteria->denied = 'not 1';`  
> **username_1**: Sure, that's an alternative. It's just calling the `setAttribute` method behind the scenes anyway.  

---

