Forum: Ruby on Rails validate uniqueness 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.
Ben M. (Guest)
on 2006-02-18 01:04
(Received via mailing list)
I have Proposals and Members and Members can vote for a proposal only

So, I have "Vote belongs_to :member, :proposal", but to make sure a
member only votes
once, I want to make sure that there isn't a vote in the db with that
member_id and
proposal_id. I can just put the appropriate find in a vote.valid? but I
wanted to make
sure I wasn't missing a nice rails shortcut.

In other words, can I do something with "validates_uniqueness_of" to
make it consider a
pair of columns, member_id and proposal_id?


Kent S. (Guest)
on 2006-02-18 01:16
(Received via mailing list)
You can by using trunk version of rails. Otherwise write your own
validate method.

Ben M. (Guest)
on 2006-02-18 01:55
(Received via mailing list)
This topic is locked and can not be replied to.