Sha256: 56d5d4f2d223bc22d8a0e7674ce0fdd22d8a8f29aa94f4d7a44fe8b1212cca5f

Contents?: true

Size: 914 Bytes

Versions: 3

Compression:

Stored size: 914 Bytes

Contents

# 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.

class Tagging < ActiveRecord::Base 
 
  belongs_to :<%= parent_association_name -%><%= ", :foreign_key => \"#{parent_association_name}_id\", :class_name => \"Tag\"" if options[:self_referential] %>
  belongs_to :taggable, :polymorphic => true
  
  # 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.
  # acts_as_list :scope => :taggable
    
  # This callback makes sure that an orphaned <tt>Tag</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 -%>.taggings.count == 1
  end    
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
has_many_polymorphs-2.10 generators/tagging/templates/tagging.rb
has_many_polymorphs-2.9 generators/tagging/templates/tagging.rb
has_many_polymorphs-2.11 generators/tagging/templates/tagging.rb