Forum: Ruby on Rails .exists?

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.
ne h. (Guest)
on 2007-06-26 19:09
Is there any way to use .exists? to check multiple conditions? Ideally,
I'd like to verify it against four other fields. Thanks in advance!


if Contact.exists?(:mobilephone => @contact.mobilephone)
Chris H. (Guest)
on 2007-06-26 19:22
(Received via mailing list)
Model.exists?(:attr1 => "x", :attr2 => "y", :attr3 => "z")

note that the the conditions will be ANDed.  if you need to use OR,
then you need to use a different conditions format

Model.exists?(["attr1 = ? OR att1 = ?", x, y])

Chris
This topic is locked and can not be replied to.