views:

110

answers:

2

i should check whether there is some values based on this condition. if there is some, then i should do one action or else do a different action. i work on rails, mysql and xp
this is not working @test.nil?
suggest me a alternate way
@test=Model.find(:all,:conditions=>"id=@someid")
thanks in advance

+6  A: 
John Topley
+5  A: 

If you're doing Model.find(:all, :conditions => '...') you'll get an empty array back if nothing can be found, not nil.

If you want to see whether there's anything matching those conditions and don't want to do anything with the actual results you can just do Model.count(:conditions => '...').

But, as your conditions just use the id you'd probably be better off checking if the object exists by doing Model.exists?(id) and then Model.find(id) if it does.

Shadwell