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
> 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
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 ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Am Dienstag, den 13.12.2005, 19:41 +0000 schrieb Hugh Sasse:> 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, > HughIf 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.
On Tue, 13 Dec 2005, Francois Beausoleil wrote:> Hi !2005/12/13, Hugh Sasse <hgs-C9usXPTk/FFaa/9Udqfwiw@public.gmane.org>:> > 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 haveThank 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 ! > -- > Franois Beausoleil >Hugh>_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails