Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Created February 27, 2009 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duncanbeevers/71604 to your computer and use it in GitHub Desktop.
Save duncanbeevers/71604 to your computer and use it in GitHub Desktop.
class Tag < ActiveRecord::Base
has_many :taggings
end
class Tagging < ActiveRecord::Base
set_inheritance_column nil
belongs_to :tag
belongs_to :posts
end
class ImportantTagging < Tagging
# uses a string 'flag' column but could be changed to a boolean important
# column later, hence the need to encapsulate!
default_scope :conditions => { :flag => 'important' }
end
class Post < ActiveRecord::Base
has_many :taggings
has_many :important_taggings
has_many :tags, :through => :taggings, :source => :tag
has_many :important_tags, :through => :important_taggings, :source => :tag
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment