seouri (owner)

Fork Of

Revisions

gist: 71852 Download_button fork
public
Public Clone URL: git://gist.github.com/71852.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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