Find record with "null" column

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?

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs