Add the has_many_polymorphs plugin
[cs356-p2-videostore.git] / vendor / plugins / has_many_polymorphs / generators / commenting / templates / commenting.rb
diff --git a/vendor/plugins/has_many_polymorphs/generators/commenting/templates/commenting.rb b/vendor/plugins/has_many_polymorphs/generators/commenting/templates/commenting.rb
new file mode 100644 (file)
index 0000000..f429dbc
--- /dev/null
@@ -0,0 +1,13 @@
+
+# The Commenting join model. This model is automatically generated and added to your app if you run the commenting generator.
+
+class Commenting < ActiveRecord::Base 
+  belongs_to :<%= parent_association_name -%><%= ", :foreign_key => \"#{parent_association_name}_id\", :class_name => \"Comment\"" if options[:self_referential] %>
+  belongs_to :commentable, :polymorphic => true
+  
+  # This callback makes sure that an orphaned <tt>Comment</tt> is deleted if it no longer tags anything.
+  def before_destroy
+    <%= parent_association_name -%>.destroy_without_callbacks if <%= parent_association_name -%> and <%= parent_association_name -%>.commentings.count == 1
+  end    
+end