-
-
Save cch1/88231 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
named_scope :important, :conditions => {:flag => 'important'} | |
end | |
class Post | |
# Explicitly scope the association, preserving the encapsulation of "important" | |
has_many :important_taggings, :scope => :important, :class_name => 'Tagging' | |
has_many :tags, :through => :taggings, :source => :tag | |
# Implicitly scope the association | |
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