Module: HasDynamicColumns::ActiveRecord::Relation

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

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
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
35
36
37
38
39
40
41
42
43
# File 'lib/has_dynamic_columns/active_record/v3/relation.rb', line 4

def self.included(base)
	base.class_eval do
		attr_accessor :where_dynamic_columns_values, :order_dynamic_columns_values, :joins_dynamic_columns

		# Collect all previously built join clauses
		def joins_dynamic_columns
			@joins_dynamic_columns = @joins_dynamic_columns || {}
			@joins_dynamic_columns
		end

		# Collect all where clauses
		def where_dynamic_columns_values
			@where_dynamic_columns_values || []
		end
		def where_dynamic_columns_values=values
			raise ImmutableRelation if @loaded
			@where_dynamic_columns_values ||= []
			@where_dynamic_columns_values << values
		end
		def where_dynamic_columns_values_reset
			@where_dynamic_columns_values = []
		end

		# Collect all order clauses
		def order_dynamic_columns_values
			@order_dynamic_columns_values || []
		end
		def order_dynamic_columns_values=values
			raise ImmutableRelation if @loaded
			@order_dynamic_columns_values ||= []
			@order_dynamic_columns_values << values
		end
		def order_dynamic_columns_values_reset
			@order_dynamic_columns_values = []
		end
	end

	base.instance_eval do
	end
end