Skip to content

Instantly share code, notes, and snippets.

@brentmc79
Created April 12, 2009 16:32
Show Gist options
  • Save brentmc79/94052 to your computer and use it in GitHub Desktop.
Save brentmc79/94052 to your computer and use it in GitHub Desktop.
class Book < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
end
class Movie < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
end
class Tag < ActiveRecord::Base
has_many :taggings, :dependent => :destroy
has_many :books, :through => :tagings, :source => :taggable, :source_type => "Book"
has_many :movies, :through => :tagings, :source => :taggable, :source_type => "Movie"
end
class Tagging < ActiveRecord::Base
belongs_to :taggable, :polymorphic => true
belongs_to :tag
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment