forest_admin_datasource_active_record 1.0.0.pre.beta.58 → 1.0.0.pre.beta.60
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/forest_admin_datasource_active_record/collection.rb +1 -1
- data/lib/forest_admin_datasource_active_record/utils/active_record_serializer.rb +9 -5
- data/lib/forest_admin_datasource_active_record/utils/query.rb +12 -1
- data/lib/forest_admin_datasource_active_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06eb4e50d70ed020e78c247129d24f1a514efcc8e3150864ac00e2a420d715ed
|
4
|
+
data.tar.gz: e11b2afab09fbf5ac3e9555a288f70638e2c01e5d2135a983b8601324d701916
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 895ce913914b2400d39f09b197ef29e25524bcd524e75749a206cb5be6797665f026eac1ab0f99bceff4b11d9546c56edd3e92155c90a68434705faba6b411ec
|
7
|
+
data.tar.gz: 5afa4e3d45800cce7d9f1a274eba8ccaf78d5c473460e1ccc56dada1064319d7e5d4b1a81b53ccadf293a64f61a1d607021665c6fdee7d95f1f143af4051d29f
|
@@ -22,7 +22,7 @@ module ForestAdminDatasourceActiveRecord
|
|
22
22
|
def list(_caller, filter, projection)
|
23
23
|
query = Utils::Query.new(self, projection, filter)
|
24
24
|
|
25
|
-
query.get.map { |record| Utils::ActiveRecordSerializer.new(record).to_hash }
|
25
|
+
query.get.map { |record| Utils::ActiveRecordSerializer.new(record).to_hash(projection) }
|
26
26
|
end
|
27
27
|
|
28
28
|
def aggregate(_caller, filter, aggregation, limit = nil)
|
@@ -1,20 +1,24 @@
|
|
1
1
|
module ForestAdminDatasourceActiveRecord
|
2
2
|
module Utils
|
3
3
|
ActiveRecordSerializer = Struct.new(:object) do
|
4
|
-
def to_hash
|
5
|
-
hash_object(object)
|
4
|
+
def to_hash(projection)
|
5
|
+
hash_object(object, projection)
|
6
6
|
end
|
7
7
|
|
8
|
-
def hash_object(object, with_associations: true)
|
8
|
+
def hash_object(object, projection = nil, with_associations: true)
|
9
9
|
hash = {}
|
10
10
|
|
11
|
-
return
|
11
|
+
return if object.nil?
|
12
12
|
|
13
13
|
hash.merge! object.attributes
|
14
14
|
|
15
15
|
if with_associations
|
16
16
|
each_association_collection(object) do |association_name, item|
|
17
|
-
hash[association_name] = hash_object(
|
17
|
+
hash[association_name] = hash_object(
|
18
|
+
item,
|
19
|
+
projection.relations[association_name],
|
20
|
+
with_associations: projection.relations.key?(association_name)
|
21
|
+
)
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
@@ -109,7 +109,8 @@ module ForestAdminDatasourceActiveRecord
|
|
109
109
|
def apply_select
|
110
110
|
unless @projection.nil?
|
111
111
|
@query = @query.select(@select.join(', '))
|
112
|
-
|
112
|
+
|
113
|
+
@query = @query.includes(format_relation_projection(@projection))
|
113
114
|
end
|
114
115
|
|
115
116
|
@query
|
@@ -144,6 +145,16 @@ module ForestAdminDatasourceActiveRecord
|
|
144
145
|
@query.send(aggregator, query)
|
145
146
|
end
|
146
147
|
end
|
148
|
+
|
149
|
+
def format_relation_projection(projection)
|
150
|
+
result = {}
|
151
|
+
projection&.relations&.each do |relation, projection_relation|
|
152
|
+
formatted_relations = format_relation_projection(projection_relation)
|
153
|
+
|
154
|
+
result[relation.to_sym] = formatted_relations
|
155
|
+
end
|
156
|
+
result
|
157
|
+
end
|
147
158
|
end
|
148
159
|
end
|
149
160
|
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.60
|
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-
|
12
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|