has_dynamic_columns 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca96bb424702503964607990ceaf8bd1f1d295d
|
4
|
+
data.tar.gz: a58a689b2bd09f47717d03f46eb159642c9ed585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d28daa53d39118043b48317fa1528a858f4879700314f1409c3c85be2e5d75da596d68c6ff82c0c215b7ef98754861f8c35707a6398addefa35a458f856007d4
|
7
|
+
data.tar.gz: 809f23544abba7769655652fe364e58a1d697133ffebf721a813b8301526b4edb624121f25e9d4f91f634413f42f0d34a7b84d8f2e00981a1cb873b55d45a13b
|
data/README.md
CHANGED
@@ -35,6 +35,7 @@ running the following command:
|
|
35
35
|
rails generate has_dynamic_columns:active_record
|
36
36
|
rails generate has_dynamic_columns:upgrade_0_3_0_active_record
|
37
37
|
rails generate has_dynamic_columns:upgrade_0_3_4_active_record
|
38
|
+
rails generate has_dynamic_columns:upgrade_0_3_5_active_record
|
38
39
|
rake db:migrate
|
39
40
|
|
40
41
|
Usage
|
@@ -38,13 +38,15 @@ module HasDynamicColumns
|
|
38
38
|
rel.expr.name = :value
|
39
39
|
# We can work with this
|
40
40
|
else
|
41
|
-
|
42
|
-
|
41
|
+
if rel.left.relation.respond_to?(:engine)
|
42
|
+
col_name = rel.left.name
|
43
|
+
dynamic_type = rel.left.relation.engine.to_s
|
43
44
|
|
44
|
-
|
45
|
+
res = dynamic_column_build_arel_joins(col_name, dynamic_type, scope, index+1, joins) # modify the where to use the aliased table
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
rel.left.relation = res[:table]
|
48
|
+
rel.left.name = res[:column] || :value # value is the data storage column searchable on dynamic_column_data table
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
@@ -154,17 +156,14 @@ module HasDynamicColumns
|
|
154
156
|
|
155
157
|
# Builds all the joins required for the dynamic columns in the where/order clauses
|
156
158
|
def build_dynamic_column_joins
|
157
|
-
joins =
|
159
|
+
joins = self.joins_dynamic_columns
|
158
160
|
|
159
161
|
self.where_dynamic_columns_values.each_with_index { |dynamic_scope, index_outer|
|
160
162
|
dynamic_scope[:where].each_with_index { |rel, index_inner|
|
161
163
|
# Process each where
|
162
164
|
dynamic_column_process_arel_nodes(rel, dynamic_scope[:scope], (index_outer*1000)+(index_inner*10000), joins)
|
163
165
|
|
164
|
-
|
165
|
-
# Must cast rel to a string - I've encountered ***strange*** situations where this will change the 'col_name' to value in the where clause
|
166
|
-
# specifically, the test 'case should restrict if scope specified' will fail
|
167
|
-
self.where_values += [rel.to_sql]
|
166
|
+
self.where_values += [rel]
|
168
167
|
}
|
169
168
|
}
|
170
169
|
self.order_dynamic_columns_values.each_with_index { |dynamic_scope, index_outer|
|
@@ -3,7 +3,13 @@ module HasDynamicColumns
|
|
3
3
|
module Relation
|
4
4
|
def self.included(base)
|
5
5
|
base.class_eval do
|
6
|
-
attr_accessor :where_dynamic_columns_values, :order_dynamic_columns_values
|
6
|
+
attr_accessor :where_dynamic_columns_values, :order_dynamic_columns_values, :joins_dynamic_columns
|
7
|
+
|
8
|
+
# Collect all previously built join clauses
|
9
|
+
def joins_dynamic_columns
|
10
|
+
@joins_dynamic_columns = @joins_dynamic_columns || {}
|
11
|
+
@joins_dynamic_columns
|
12
|
+
end
|
7
13
|
|
8
14
|
# Collect all where clauses
|
9
15
|
def where_dynamic_columns_values
|
@@ -5,6 +5,12 @@ module HasDynamicColumns
|
|
5
5
|
module Relation
|
6
6
|
def self.included(base)
|
7
7
|
base.class_eval do
|
8
|
+
# Collect all where clauses
|
9
|
+
def joins_dynamic_columns
|
10
|
+
@values[:joins_dynamic_columns] = @values[:joins_dynamic_columns] || {}
|
11
|
+
@values[:joins_dynamic_columns]
|
12
|
+
end
|
13
|
+
|
8
14
|
# Collect all where clauses
|
9
15
|
def where_dynamic_columns_values
|
10
16
|
@values[:where_dynamic_columns_values] || []
|