aboutsummaryrefslogblamecommitdiffstats
path: root/app/models/blog_category.rb
blob: 89bff27ad958fe5bb86219971fd595c789cf8ebb (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                       

                                                           





                                           
 


                                                    
 


                           
 

         
 
   
class BlogCategory < ActiveRecord::Base

  has_and_belongs_to_many :posts, :class_name => 'BlogPost'

  acts_as_indexed :fields => [:title]

  validates_presence_of :title
  validates_uniqueness_of :title

  has_friendly_id :title, :use_slug => true

  # this might be able to be optimised a little more
  def post_count
    count = 0

    self.posts.each do |p|
      count += 1 if p.live?
    end

    count
  end

end