Add the has_many_polymorphs plugin
[cs356-p2-videostore.git] / vendor / plugins / has_many_polymorphs / generators / commenting / templates / commenting.rb
1
2 # The Commenting join model. This model is automatically generated and added to your app if you run the commenting generator.
3
4 class Commenting < ActiveRecord::Base 
5  
6   belongs_to :<%= parent_association_name -%><%= ", :foreign_key => \"#{parent_association_name}_id\", :class_name => \"Comment\"" if options[:self_referential] %>
7   belongs_to :commentable, :polymorphic => true
8   
9   # This callback makes sure that an orphaned <tt>Comment</tt> is deleted if it no longer tags anything.
10   def before_destroy
11     <%= parent_association_name -%>.destroy_without_callbacks if <%= parent_association_name -%> and <%= parent_association_name -%>.commentings.count == 1
12   end    
13 end