Validate uniqueness of two fields


#1

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


#2

You can by using trunk version of rails. Otherwise write your own
validate method.


Kent

http://www.datanoise.com


#3

thanks…