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.
4005a47a8f2ceee49670b920593c1d52?d=identicon&s=25 Ben Munat (Guest)
on 2006-02-18 00: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?


3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-02-18 00:16
(Received via mailing list)
You can by using trunk version of rails. Otherwise write your own
validate method.

4005a47a8f2ceee49670b920593c1d52?d=identicon&s=25 Ben Munat (Guest)
on 2006-02-18 00:55
(Received via mailing list)
This topic is locked and can not be replied to.