Skip to content

Instantly share code, notes, and snippets.

@ianwhite
Forked from lukeredpath/gist:71585
Created February 27, 2009 18:09
Show Gist options
  • Save ianwhite/71609 to your computer and use it in GitHub Desktop.
Save ianwhite/71609 to your computer and use it in GitHub Desktop.
# just using ruby (see below) makes for a pretty easy fix in this case, but it could
# get pretty ugly pretty quick which a real world case. Having a 'One True Namespace'
# for conditions would keep the ugly at bay.
#
# So, I think I like the idea of using named_scope as a namespace for conditions (ie
# Luke's idea)
class Tag
has_many :taggings
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!
ImportantConditions = {:flag => 'important'}
named_scope :important, :conditions => ImportantConditions
end
class Post
has_many :taggings
has_many :tags, :through => :taggings, :source => :tag
has_many :important_tags, :through => :taggings, :source => :tag, :conditions => Tagging::ImportantConditions
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment