tracks/app/models/tagging.rb

21 lines
423 B
Ruby
Raw Normal View History

2008-12-22 23:26:38 +01:00
# The Tagging join model.
2008-12-22 23:26:38 +01:00
class Tagging < ActiveRecord::Base
attr_accessible :taggable_id, :tag
2008-12-22 23:26:38 +01:00
belongs_to :tag
belongs_to :taggable, :polymorphic => true, :touch => true
after_destroy :after_destroy
private
2008-12-22 23:26:38 +01:00
# This callback makes sure that an orphaned <tt>Tag</tt> is deleted if it no longer tags anything.
def after_destroy
tag.destroy if tag and tag.taggings.count == 0
end
2008-12-22 23:26:38 +01:00
end