# Validating uniquesness through double association?

**URL:** <https://www.ruby-forum.com/t/validating-uniquesness-through-double-association/92252>\
**Category:** Rails\
**Created:** [April 17, 2007, 2:40pm UTC](https://www.ruby-forum.com/t/validating-uniquesness-through-double-association/92252 "2007-04-17T14:40:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 17, 2007, 2:40pm UTC](https://www.ruby-forum.com/t/validating-uniquesness-through-double-association/92252/1 "2007-04-17T14:40:10Z")

</div>

Hello all!

Could someone give me idea how to solve following problem.

In the model:

class A \< ActiveRecord::Base  
has\_many :B  
end

class B \< ActiveRecord::Base  
belongs\_to :A  
has\_and\_belongs\_to\_many :C  
end

class C \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :B  
end

Is it possible to validate that C has only B’s that belong to the same  
A ? %)

Will be happy to see any answers))
