# Help with query and testing array

**URL:** <https://www.ruby-forum.com/t/help-with-query-and-testing-array/111407>\
**Category:** Rails\
**Created:** [August 7, 2007, 12:32am UTC](https://www.ruby-forum.com/t/help-with-query-and-testing-array/111407 "2007-08-07T00:32:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 7, 2007, 12:32am UTC](https://www.ruby-forum.com/t/help-with-query-and-testing-array/111407/1 "2007-08-07T00:32:31Z")

</div>

I am working on an app with a Flex front end and part of that is to  
search for an  
institution by name.

I have it working if the user enters the school name exactly, but I  
need to deal with  
multiple results being returned, specifically how to test if multiple  
results were  
returned, if they are to change the SQL statement.

Code with notes below:

@query = params[:iname][:id] \<-- an xml result from Flex  
@new\_query = “%” +@query+ “%”

@institutions = Institution.find(:all, :conditions =\>  
[“institution\_name like ?”, @new\_query])

if @institutions.length \> 1  
@inst\_query = “institution\_id in”  
for institution in @institutions  
@inst\_id \<\< institution.id  
end  
end

@events = Event.find(:all, :conditions =\> ["(institution\_id = ?)",  
@institutions], :order =\> “event\_start\_date”)

Note - the code is not working as above. I will need to change the  
query to be (institution\_id IN (x,x,x)).

When I test for length I get an error about nil object.

Thanks in advance for your help.

-Scott
