# Lazy boolean tests in SQL?

**URL:** <https://www.ruby-forum.com/t/lazy-boolean-tests-in-sql/125379>\
**Category:** Rails\
**Created:** [January 8, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/lazy-boolean-tests-in-sql/125379 "2008-01-08T18:19:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [January 8, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/lazy-boolean-tests-in-sql/125379/1 "2008-01-08T18:19:52Z")

</div>

I’m doing a ferret find\_by\_contents search which searches multiple  
tables. One of the conditions i’m putting through is a test on a column  
that some of the tables don’t have, which is making the test crash.

To be specific, i’m searching on Lesson, Course and Resource, and one of  
the conditions relates to a field ‘kind\_id’, which is only possessed by  
the ‘resources’ table.

To get around this, i put in another test first, on a ‘type’ field,  
which is set to ‘Resource’ for all rows in the ‘Resource’ table. I  
thought that this would mean that kind\_id was only tested on rows from  
the resources table, but it’s not working - the test still fails as  
kind\_id is being evaluated against tables that don’t have the field.

My value for the conditions key is

conditions \<\< “type = ‘Resource’ AND kind\_id IN  
(#{params[:kinds].collect{|k| k.to\_s}.join(”,")})"

which evaluates to something like

conditions \<\< “type = ‘Resource’ AND kind\_id IN (“1”,“4”,“8”)”

So, basically i need the SQL test to be lazy, and not evaluate kind\_id  
if the first test fails. Is this possible? If not, can anyone see a  
different way around this? For example, can i only test the kind\_id  
conditions on rows from a specific table?

thanks, max
