Sha256: 9c8ec76ff6c62d5a83b713266582c0a057915dee6cc2b1ed40c4d3c362d5ba0f

Contents?: true

Size: 554 Bytes

Versions: 4

Compression:

Stored size: 554 Bytes

Contents

module Hatchy
  class Category < ActiveRecord::Base
    has_many :projects, class_name:'Hatchy::Project'
    has_many :category_followers
    has_many :users, through: :category_followers
    validates :name, presence: true, uniqueness: true

    def self.with_projects
      where("exists(select * from hatchy_projects where hatchy_projects.category_id = hatchy_categories.id and hatchy_projects.status not in('draft', 'rejected'))")
    end

    def total_projects
      @total_projects ||= self.projects.where(status:'online').count
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hatchy-0.0.8.pre app/models/hatchy/category.rb
hatchy-0.0.7.pre app/models/hatchy/category.rb
hatchy-0.0.6.pre app/models/hatchy/category.rb
hatchy-0.0.5.pre app/models/hatchy/category.rb