Class: Rea::Category

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/rea/category.rb

Class Method Summary collapse

Class Method Details

.for(entity_or_class, attribute) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/rea/category.rb', line 12

def self.for entity_or_class, attribute
  group_ids =
	(entity_or_class.is_a? Class) ? [entity_or_class.default_group.id] : entity_or_class.group_ids
  class_name = 
	(entity_or_class.is_a? Class) ? entity_or_class.name : entity_or_class.class.name
  entity = entity_or_class
  self.joins(:groups, :classification).where(
	:"rea_groups.id"=>group_ids,
	:"rea_classifications.name"=>attribute,
	:"rea_classifications.type_name"=>class_name
  )
end