There is a validation that will check the length of your association. Try this:
class Product < ActiveRecord::Base
has_many :product_categories
has_many :categories, :through => :product_categories
validates :categories, :length => { :minimum => 1 }
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…