Skip to content

Instantly share code, notes, and snippets.

@ryanb
Forked from lukeredpath/gist:71585
Created February 27, 2009 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanb/71618 to your computer and use it in GitHub Desktop.
Save ryanb/71618 to your computer and use it in GitHub Desktop.
class Tag
has_many :taggings
named_scope :important, :include => { :taggings => :important }
end
class Tagging
belongs_to :tag
belongs_to :posts
# uses a string 'flag' column but could be changed to a boolean important
# column later, hence the need to encapsulate!
named_scope :important, :conditions => {:flag => 'important'}
end
class Post
has_many :taggings
has_many :tags, :through => :taggings, :source => :tag
end
# post.tags.important
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment