Ank Ag wrote:> Hello,
> Can anyone please tell me how do i write a sql query in rails in which
> only one field in not null and the others are null.
>
> FOr e.g. i want to find all records in which email is not null and all
> the other fields are null. I do not want to mention the null fields
> explicitly in query because there are many of them.
>
> Thank you.
not sure of the best way, here is one though:
imagine your object is called Business
@business = Business.find_by_sql([''SELECT * FROM business WHERE email
!=
null AND column2 = null AND column3 = null AND column4 = null''])
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001377
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---