I need to ensure that when a product is created it has atleast one category. I could do this with a custom validation class, but I was hoping there was a more standard way of doing it.
class Product < ActiveRecord::Base
has_many :product_categories
has_many :categories, :through => :product_categories #must have at least 1
end
class Category < ActiveRecord::Base
has_many :product_categories
has_many :products, :through => :product_categories
end
class ProductCategory < ActiveRecord::Base
belongs_to :product
belongs_to :category
end