# Find record with "null" column

**URL:** <https://www.ruby-forum.com/t/find-record-with-null-column/134840>\
**Category:** Rails\
**Created:** [April 15, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/find-record-with-null-column/134840 "2008-04-15T15:34:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [April 15, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/find-record-with-null-column/134840/1 "2008-04-15T15:34:11Z")

</div>

How do I find a record in my database with a column that is “null” or  
empty.

Right now I am using:

@folder = Folder.find(:all, :conditions =\> “folder\_id IS NULL”)

Based on this query which is tested to work on my database:

SELECT \* FROM folders WHERE folder\_id IS NULL;

Ruby on rails does not return any error message, but when I call:

@folder.id

respectively, it returns the value of the object\_id. It seems, that the  
value doesn’t exist, and it returns the object\_id instead.

Do anyone know a solution of this problem?

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [April 15, 2008, 3:38pm UTC](https://www.ruby-forum.com/t/find-record-with-null-column/134840/2 "2008-04-15T15:38:28Z")

</div>

On 15 Apr 2008, at 14:34, David T. wrote:

> @folder = Folder.find(:all, :conditions =\> “folder\_id IS NULL”)

…

> Ruby on rails does not return any error message, but when I call:
> 
> @folder.id
> 
> respectively, it returns the value of the object\_id. It seems, that  
> the  
> value doesn’t exist, and it returns the object\_id instead.

find :all returns an array of objects not a single object (so there  
you’re asking for the id of the array containing the results)

Fred

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [April 15, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/find-record-with-null-column/134840/3 "2008-04-15T16:10:34Z")

</div>

Frederick C. wrote:

> find :all returns an array of objects not a single object (so there  
> you’re asking for the id of the array containing the results)

Thank you. I didn’t think of that. I’m using :first instead, it works.
