Forum: Ruby on Rails find()ing rows w/ NULL columns?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 Hugh Sasse (Guest)
on 2005-12-13 20:43
(Received via mailing list)
Agile Web Development with Rails doesn't seem to have NULL in the
index [or my eyes have failed me again], and web searching turns up
lots of SQL statements containing NOT NULL.

I have a table of loans, and I want to record when something was
loaned and returned.  The loan date can't be null, or there'd be
no entry in the table.  The return date must be something until
the item is returned, and NULL seems a sensible sentinal value.

How does one
   Loan.find(:all, :conditions => [":return = ?" , something])
to pick up the null entries, thus items that haven't been returned?
I'm thinking that ":return = NULL" might match a string "NULL", but
can't find confirmation or denial of this...

Maybe there's another idiom for this kind of problem?  (Setting a
return date in the year 3000 seems like a bodge, and it would
overflow Unix ideas of time anyway...)

        Thank you,
        Hugh
3dd4b52a0946bd698b1d1635a46ea3a3?d=identicon&s=25 Francois Beausoleil (Guest)
on 2005-12-13 20:46
(Received via mailing list)
Hi !

2005/12/13, Hugh Sasse <hgs@dmu.ac.uk>:
> How does one
>    Loan.find(:all, :conditions => [":return = ?" , something])
> to pick up the null entries, thus items that haven't been returned?
> I'm thinking that ":return = NULL" might match a string "NULL", but
> can't find confirmation or denial of this...

Load.find(:all, :conditions => 'return IS NULL')

Also, note that in your original code you put ':return' (note the
colon).  That would have given you an error since Rails would have
tried to replace :return with a value, but would not have found
anything in something (not being a Hash).

Hope that helps !
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2005-12-13 20:46
(Received via mailing list)
> How does one
>    Loan.find(:all, :conditions => [":return = ?" , something])
> to pick up the null entries, thus items that haven't been returned?
> I'm thinking that ":return = NULL" might match a string "NULL", but
> can't find confirmation or denial of this...

Loan.find(:all, :conditions => 'return IS NULL')

--
rick
http://techno-weenie.net
953c18019bceaa294ae0429bef6ab388?d=identicon&s=25 Norman Timmler (Guest)
on 2005-12-13 20:58
(Received via mailing list)
Am Dienstag, den 13.12.2005, 19:41 +0000 schrieb Hugh Sasse:
>    Loan.find(:all, :conditions => [":return = ?" , something])
> to pick up the null entries, thus items that haven't been returned?
> I'm thinking that ":return = NULL" might match a string "NULL", but
> can't find confirmation or denial of this...
>
> Maybe there's another idiom for this kind of problem?  (Setting a
> return date in the year 3000 seems like a bodge, and it would
> overflow Unix ideas of time anyway...)
>
>         Thank you,
>         Hugh
If you want to find all records with NULL values in field return use
this line:

Loan.find(:all, :conditions => 'return IS NULL')

Don't know if this is exactly what you wanted.
457cf540784a12ba2f30e06565a2c189?d=identicon&s=25 Hugh Sasse (Guest)
on 2006-01-01 21:33
(Received via mailing list)
On Tue, 13 Dec 2005, Francois Beausoleil wrote:

> Hi !

2005/12/13, Hugh Sasse <hgs@dmu.ac.uk>:
> > How does one
> >    Loan.find(:all, :conditions => [":return = ?" , something])
> > to pick up the null entries, thus items that haven't been returned?
> > I'm thinking that ":return = NULL" might match a string "NULL", but
> > can't find confirmation or denial of this...
>
> Load.find(:all, :conditions => 'return IS NULL')

thank you, and the others who said the same.
>
> Also, note that in your original code you put ':return' (note the
> colon).  That would have given you an error since Rails would have

Thank you, I was too hasty in composing that :-)

> tried to replace :return with a value, but would not have found
> anything in something (not being a Hash).
>
> Hope that helps !
> --
> François Beausoleil
>
        Hugh
This topic is locked and can not be replied to.