Add the has_many_polymorphs plugin
[cs356-p2-videostore.git] / vendor / plugins / has_many_polymorphs / generators / tagging / templates / tagging.rb
1
2 # The Tagging join model. This model is automatically generated and added to your app if you run the tagging generator included with has_many_polymorphs.
3
4 class Tagging < ActiveRecord::Base 
5  
6   belongs_to :<%= parent_association_name -%><%= ", :foreign_key => \"#{parent_association_name}_id\", :class_name => \"Tag\"" if options[:self_referential] %>
7   belongs_to :taggable, :polymorphic => true
8   
9   # If you also need to use <tt>acts_as_list</tt>, you will have to manage the tagging positions manually by creating decorated join records when you associate Tags with taggables.
10   # acts_as_list :scope => :taggable
11     
12   # This callback makes sure that an orphaned <tt>Tag</tt> is deleted if it no longer tags anything.
13   def before_destroy
14     <%= parent_association_name -%>.destroy_without_callbacks if <%= parent_association_name -%> and <%= parent_association_name -%>.taggings.count == 1
15   end    
16 end