activerecord - Check if Rails Database Query Returns Nothing -


I want to know if a railway database query returns a row or not (I do not need to know that the row , If just one row comes back).

I can do this:

  academic_yire = academic yair.find_b ____ input (year) if academic_array ... end   

but If I type incorrectly and a find_all_by :

  academic_all = academic yair.find_all_b ____ input (year)   

then a blank The array has been returned, due to which the if statement is correct.

I know, I need to be careful and just call all , but there is a Rail-Asc call to see if any questions ( all < / Code> or not) returns result from zero ?

As you said, find_by _... back zero [] will return and search_full____. . I think that what you see is that.

  if! Academic_thank.bank? # ... end   

in console

  & gt; AcademicYear.find_by_raw_input (some_non_existent_year) .blank? = & Gt; True & gt; AcademicYear.find_all_by_raw_input (some_non_existent_year) .blank? = & Gt; True    

Comments