Forum: Ruby on Rails Validating the uniqueness of the combination of two fields

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
933c05ef3dbe1454bd213bc08777ef63?d=identicon&s=25 macarthy (Guest)
on 2007-02-20 20:21
(Received via mailing list)
Is there a built-in method to validate that two fields in combination
are unique?

e.g. if my table is :

username  | password
user1        | pass1

the following happens>"user1",password=>"pass2")  => ok>"user2",password=>"pass1")  => ok>"user1",password=>"pass1")  => not ok

8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2007-02-21 01:56
(Received via mailing list)
I am interested in this too.  Does anybody have any ideas?
3b4506ae582cefb19270ac601c302bf0?d=identicon&s=25 bandito (Guest)
on 2007-02-21 02:14
(Received via mailing list)
validates_uniqueness_of :username, :scope => :password

(this is an extra query. You could write a unique index and rescue the
This topic is locked and can not be replied to.