Validates_uniqueness_of on has_and_belongs_to_many

I am trying to create a model that allows only unique assets to be
added to a category. However, they could be added again to a different
category. Finally, an asset can be shared across many categories. So
my question is how do you check the uniqueness across a join table?

This does not compile…

has_and_belongs_to_many :categories, :foreign_key => ‘asset_id’
validates_uniqueness_of :data, :scope => ‘asset_categories.category_id’