Forum: Ruby on Rails validates_uniqueness_of AND join tables

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.
0612733748b42ad784fdfd27ee87427f?d=identicon&s=25 David Modernfossil (modernfossil)
on 2007-06-03 05:49
I have organizations and individuals.  Both of these can have multiply
urls, emails, addresses or I have used a join table.  I also
have codes - WK - work, HM - Home...etc.  I need to validate that an
individual or oranization can only have one type of email, phone...etc.

For example an individual can only have multiple email address but only
one with type "WK".  How would I validate this accross the join table.

In the email model I have this:

validates_uniqueness_of :type_cd, :scope => "individual_id"

but it doesn't seem to know about individual_id in this context???

72eb65fa089082d3bd8b38a5596ad331?d=identicon&s=25 Keynan Pratt (keynan)
on 2007-06-03 08:45
The validation must be paced on the join table

you'll need to validate the uniquness of the two id's and a type field.
This topic is locked and can not be replied to.