forest_admin_datasource_active_record 1.0.0.pre.beta.54 → 1.0.0.pre.beta.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d6fb52bad1ecc5a281b51414badded38a6c4ff12eb0fa5d31b9daf6acea83bc
|
4
|
+
data.tar.gz: 8fd24a8be2d94a2dd617ab3e65cbe958bb2e16d345f3ad15a89f66019e78df31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67d89437e303f22b0e860c5753b50d225a59949947d6fa4135ce5332bc2609a648bbc424b0c18d173b379d10f40338a10252872245917726129f659ef9bf7afb
|
7
|
+
data.tar.gz: 7994813a226847201d9aab32d68250c17216bf9e471970fba73b8ee06d42c45557e50af02ecb8f3a614feb4f735a0cb796a58b11cda46722d58246396a8c75a4
|
@@ -50,39 +50,41 @@ module ForestAdminDatasourceActiveRecord
|
|
50
50
|
|
51
51
|
def apply_condition_tree(condition_tree, aggregator = nil)
|
52
52
|
if condition_tree.is_a? Nodes::ConditionTreeBranch
|
53
|
-
aggregator = condition_tree.aggregator.downcase
|
53
|
+
aggregator = condition_tree.aggregator.downcase.to_sym
|
54
54
|
condition_tree.conditions.each do |condition|
|
55
|
-
query = apply_condition_tree(condition, aggregator)
|
56
|
-
@query = @query.send(aggregator, query)
|
55
|
+
@query = apply_condition_tree(condition, aggregator)
|
56
|
+
@query = @query.send(aggregator, @query)
|
57
57
|
end
|
58
58
|
|
59
59
|
@query
|
60
60
|
else
|
61
|
-
compute_main_operator(condition_tree, aggregator ||
|
61
|
+
@query = compute_main_operator(condition_tree, aggregator || :and)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
def compute_main_operator(condition_tree, aggregator)
|
66
66
|
field = format_field(condition_tree.field)
|
67
67
|
value = condition_tree.value
|
68
|
+
aggregator = aggregator.to_sym
|
68
69
|
|
69
70
|
case condition_tree.operator
|
70
71
|
when Operators::PRESENT
|
71
|
-
@query =
|
72
|
+
@query = query_aggregator(aggregator, @collection.model.where.not({ field => nil }))
|
72
73
|
when Operators::EQUAL, Operators::IN
|
73
|
-
@query =
|
74
|
+
@query = query_aggregator(aggregator, @collection.model.where({ field => value }))
|
74
75
|
when Operators::NOT_EQUAL, Operators::NOT_IN
|
75
|
-
@query =
|
76
|
+
@query = query_aggregator(aggregator, @collection.model.where.not({ field => value }))
|
76
77
|
when Operators::GREATER_THAN
|
77
|
-
@query =
|
78
|
+
@query = query_aggregator(aggregator, @collection.model.where(@arel_table[field.to_sym].gt(value)))
|
78
79
|
when Operators::LESS_THAN
|
79
|
-
@query =
|
80
|
+
@query = query_aggregator(aggregator, @collection.model.where(@arel_table[field.to_sym].lt(value)))
|
80
81
|
when Operators::NOT_CONTAINS
|
81
|
-
@query =
|
82
|
+
@query = query_aggregator(aggregator,
|
83
|
+
@collection.model.where.not(@arel_table[field.to_sym].matches("%#{value}%")))
|
82
84
|
when Operators::LIKE
|
83
|
-
@query =
|
85
|
+
@query = query_aggregator(aggregator, @collection.model.where(@arel_table[field.to_sym].matches(value)))
|
84
86
|
when Operators::INCLUDES_ALL
|
85
|
-
@query =
|
87
|
+
@query = query_aggregator(aggregator, @collection.model.where(@arel_table[field.to_sym].matches_all(value)))
|
86
88
|
end
|
87
89
|
|
88
90
|
@query
|
@@ -93,7 +95,7 @@ module ForestAdminDatasourceActiveRecord
|
|
93
95
|
@select += @projection.columns.map { |field| "#{@collection.model.table_name}.#{field}" }
|
94
96
|
@projection.relations.each_key do |relation|
|
95
97
|
relation_schema = @collection.schema[:fields][relation]
|
96
|
-
@select << if relation_schema.type == 'OneToOne'
|
98
|
+
@select << if relation_schema.type == 'OneToOne' || relation_schema.type == 'PolymorphicOneToOne'
|
97
99
|
"#{@collection.model.table_name}.#{relation_schema.origin_key_target}"
|
98
100
|
else
|
99
101
|
"#{@collection.model.table_name}.#{relation_schema.foreign_key}"
|
@@ -107,33 +109,41 @@ module ForestAdminDatasourceActiveRecord
|
|
107
109
|
def apply_select
|
108
110
|
unless @projection.nil?
|
109
111
|
@query = @query.select(@select.join(', '))
|
110
|
-
@query = @query.
|
112
|
+
@query = @query.includes(@projection.relations.keys.map(&:to_sym))
|
111
113
|
end
|
112
114
|
|
113
115
|
@query
|
114
116
|
end
|
115
117
|
|
116
|
-
def add_join_relation(
|
117
|
-
|
118
|
-
# TODO: to implement
|
119
|
-
else
|
120
|
-
@query = @query.joins(relation_name.to_sym)
|
121
|
-
end
|
118
|
+
def add_join_relation(relation_name)
|
119
|
+
@query = @query.includes(relation_name.to_sym)
|
122
120
|
|
123
121
|
@query
|
124
122
|
end
|
125
123
|
|
126
124
|
def format_field(field)
|
125
|
+
@select << "#{@collection.model.table_name}.#{field}"
|
126
|
+
|
127
127
|
if field.include?(':')
|
128
128
|
relation_name, field = field.split(':')
|
129
129
|
relation = @collection.schema[:fields][relation_name]
|
130
130
|
table_name = @collection.datasource.get_collection(relation.foreign_collection).model.table_name
|
131
|
-
add_join_relation(
|
131
|
+
add_join_relation(relation_name)
|
132
|
+
@select << "#{table_name}.#{field}"
|
133
|
+
|
132
134
|
return "#{table_name}.#{field}"
|
133
135
|
end
|
134
136
|
|
135
137
|
field
|
136
138
|
end
|
139
|
+
|
140
|
+
def query_aggregator(aggregator, query)
|
141
|
+
if !@query.respond_to?(:where_clause) || @query.where_clause.empty?
|
142
|
+
query
|
143
|
+
else
|
144
|
+
@query.send(aggregator, query)
|
145
|
+
end
|
146
|
+
end
|
137
147
|
end
|
138
148
|
end
|
139
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forest_admin_datasource_active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.56
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-06-
|
12
|
+
date: 2024-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|