# Validates\_uniqueness\_of AND join tables

**URL:** <https://www.ruby-forum.com/t/validates-uniqueness-of-and-join-tables/105808>\
**Category:** Rails\
**Created:** [June 3, 2007, 5:49am UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-and-join-tables/105808 "2007-06-03T05:49:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [June 3, 2007, 5:49am UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-and-join-tables/105808/1 "2007-06-03T05:49:05Z")

</div>

I have organizations and individuals. Both of these can have multiply  
urls, emails, addresses or phones…so 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???

thanks

---

<div class="post-metadata">

**Author:** ![dgm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/df788c/32.png) [@dgm](https://www.ruby-forum.com/u/dgm)\
**Post date:** [June 3, 2007, 8:45am UTC](https://www.ruby-forum.com/t/validates-uniqueness-of-and-join-tables/105808/2 "2007-06-03T08:45:39Z")

</div>

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.
