Forum: Ruby on Rails validate uniqueness of two fields

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.
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
once.

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?

thanks,

b
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.


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