aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/blog_category.rb
blob: 89bff27ad958fe5bb86219971fd595c789cf8ebb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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