Method: Rea::ActiveRecordExt::ClassMethods#member

Defined in:
lib/rea/active_record_ext.rb

#member(classification, *args) ⇒ Object

[View source]

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rea/active_record_ext.rb', line 55

def member classification, *args
	((::Rea.[:member_class_names] ||= []) << self.name).uniq!
	grouping
	$options = {:multiple=>false,
	  :category_class_name=>::Rea::Category.name,
	  :categories_entity_class_name=>::Rea::CategoriesEntity.name
	}.merge(args.extract_options!)
	members[classification] = $options.dup
	if (args.size > 0) && (categories = args[0]).is_a?(Array)
	  members[classification][:categories] = categories
	end
	if $options[:multiple]
	  has_many :categories_entities, :as=>:entity, :class_name=>$options[:categories_entity_class_name]
	  has_many classification, :through=>:categories_entities,
	    :include=>:classification, 
	    :class_name=>$options[:category_class_name],
	    :source=>:category,
	    :conditions=>"rea_classifications.type_name = '#{self.name}' and rea_classifications.name = '#{classification.to_s.singularize}'"
	else
	  belongs_to classification, :class_name=>$options[:category_class_name]
	end
end