Validates_uniqueness_of on two columns?

I want to make sure a combination of email and name are unique in a
database
for a newsletter signup application

What would be the railsy-ish way to do it?

here are a couple of ways I can think of accomplishing this

o Extend validation

o Make a unique primary key column in the database

Clayton C.

WinterMarket Networks
Phone: (604) 417-3254
Vancouver, B.C. Canada
http://www.wintermarket.net
MSN:[email protected]
AIM:drfrogrx

I’m not sure if writing a validate method is considered “extending
validation”, but that’s the way I’d do it. And also a DB constraint;
just in case. It protects the integrity of your data regardless of
how it got there, since not all paths may be through your application.

On 9/17/06, Clayton C. [email protected] wrote:

Phone: (604) 417-3254


When a man says he approves of something in principle, it means he
hasn’t the slightest intention of putting it into practice. –
Bismarck

Clayton C. wrote the following on 17.09.2006 23:11 :

I want to make sure a combination of email and name are unique in a
database for a newsletter signup application

What would be the railsy-ish way to do it?

validates_uniqueness of :email, :scope => :name

if you want to validate uniqueness of a triplet or more

validates_uniqueness of :first_attr, :scope => [ :second_attr,
:third_attr … ]

Lionel