Validating uniquesness through double association?


#1

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))