Module: ActivePress::Taxonomy

Included in:
Category, Tag, TermTaxonomy
Defined in:
lib/active_press/taxonomy.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/active_press/taxonomy.rb', line 4

def self.included(base)
  base.instance_eval do
    set_table_name "wp_term_taxonomy"
    set_primary_key "term_taxonomy_id"
    
    belongs_to :term, :foreign_key => "term_id"
    has_many :term_relationships, :foreign_key => "term_taxonomy_id"
    has_many :posts, :through => :term_relationships
     
    delegate :name, :to => :term
    delegate :slug, :to => :term
    
    def self.find_by_slug!(slug)
      joins(:term).where('wp_terms.slug = ?', slug).first
    end
  end
end