# Using hashes as find conditions

**URL:** <https://www.ruby-forum.com/t/using-hashes-as-find-conditions/91838>\
**Category:** Rails\
**Created:** [April 12, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/using-hashes-as-find-conditions/91838 "2007-04-12T19:32:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saxon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@Saxon](https://www.ruby-forum.com/u/Saxon)\
**Post date:** [April 12, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/using-hashes-as-find-conditions/91838/1 "2007-04-12T19:32:49Z")

</div>

I’ve been having problems using hashes in conjunction with SQL. Here’s  
an example:

Question.count(:all, :conditions =\> { :parent =\> nil })

And here’s the query it runs :

SELECT count(\*) AS count\_all FROM questions WHERE (parent)

If I try to do something like:

Question.count(:all, :conditions =\> { :parent =\> 1 })

I get:

Mysql::Error: #42S22Unknown column ‘parent1’ in ‘where clause’:  
SELECT count(\*) AS count\_all FROM questions WHERE (parent1)

Why does it strip out the conditional text?

I’m running Rails 1.2.3

Thanks in advance for any help!

Saxon

---

<div class="post-metadata">

**Author:** ![Saxon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@Saxon](https://www.ruby-forum.com/u/Saxon)\
**Post date:** [April 12, 2007, 7:47pm UTC](https://www.ruby-forum.com/t/using-hashes-as-find-conditions/91838/2 "2007-04-12T19:47:51Z")

</div>

using hashed conditions only works in 1.2.x i believe.

1.1.6 behavior

{ :parent =\> nil } # =\> select \* from … where (parent)  
{ :parent =\> 1 } # =\> select \* from … where (parent1)

1.2.3 behavior

{ :parent =\> nil } # =\> select \* from … where (parent IS NULL)  
{ :parent =\> 1 } # =\> select \* from … where (parent = 1)

---

<div class="post-metadata">

**Author:** ![Saxon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@Saxon](https://www.ruby-forum.com/u/Saxon)\
**Post date:** [April 12, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/using-hashes-as-find-conditions/91838/3 "2007-04-12T19:49:51Z")

</div>

sorry, missed that you said you were using 1.2.3.

did you create your project using a previous version of rails? if so,  
check your config/environment.rb file. that will specify which  
version your project is using.

---

<div class="post-metadata">

**Author:** ![Saxon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/59ef9b/32.png) [@Saxon](https://www.ruby-forum.com/u/Saxon)\
**Post date:** [April 12, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/using-hashes-as-find-conditions/91838/4 "2007-04-12T20:14:53Z")

</div>

Well don’t I feel silly. I did in fact create the application using  
1.1.6, so I updated the number in the environment.rb file and it works  
just fine. Thank you for your help!

Saxon
