Module: HasDynamicColumns::ActiveRecord::QueryMethods::ClassMethods

Defined in:
lib/has_dynamic_columns/active_record/v3/query_methods.rb,
lib/has_dynamic_columns/active_record/v4/query_methods.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/has_dynamic_columns/active_record/v3/query_methods.rb', line 7

def self.included base
	base.class_eval do
		def preprocess_order_args(order_args)
			order_args.flatten!
			#validate_order_args(order_args)

			references = order_args.grep(String)
			references.map! { |arg| arg =~ /^([a-zA-Z]\w*)\.(\w+)/ && $1 }.compact!
			references!(references) if references.any?

			# if a symbol is given we prepend the quoted table name
			order_args.map! do |arg|
				case arg
				when Symbol
					#arg = klass.attribute_alias(arg) if klass.attribute_alias?(arg)
					table[arg].asc
				when Hash
					arg.map { |field, dir|
						#field = klass.attribute_alias(field) if klass.attribute_alias?(field)
						table[field].send(dir.downcase)
					}
				else
					arg
				end
			end.flatten!
		end
	end
end