1

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

1

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.

  • Yes this is the correct way to test for a false boolean in the database! Thanks! – SublymeRick May 8 '17 at 17:53
  • I actually ended up using $criteria->denied = 'not 1'; – SublymeRick May 8 '17 at 17:55
  • 1
    Sure, that's an alternative. It's just calling the setAttribute method behind the scenes anyway. – Stephen Lewis May 8 '17 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.