Module: CategoryDb::ClassMacros

Included in:
ActiveRecord::Base
Defined in:
lib/tagutils/categories/active_record.rb

Instance Method Summary collapse

Instance Method Details

#has_many_categories(opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/tagutils/categories/active_record.rb', line 4

def has_many_categories( opts={} )
  puts "  [CategoryDb.has_many_categories] adding categorizations n category has_many assocs to model >#{name}<"

  has_many :categorizations, class_name: 'CategoryDb::Model::Categorization', :as      => :categorizable
  has_many :categories,      class_name: 'CategoryDb::Model::Category',       :through => :categorizations

  ### check: use category_name instead of category_key  ???
  scope :with_category, ->(category_key){ joins(:categories).where('categories.key' => category_key) }
end