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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f2eaef8a89cf8ecc94aeb3f8308109a1eb975b0d407651a3e92f9dd39682fdc
4
- data.tar.gz: 4498babbc445ddad40e54a676e1a2e252740c97c598c136a80ebf2a6a1386039
3
+ metadata.gz: 06eb4e50d70ed020e78c247129d24f1a514efcc8e3150864ac00e2a420d715ed
4
+ data.tar.gz: e11b2afab09fbf5ac3e9555a288f70638e2c01e5d2135a983b8601324d701916
5
5
  SHA512:
6
- metadata.gz: 343d2c7753100824bed032f8ea060a059b3f684af87b84d3d6fa2f115913a9e4e78779912afa81db64e1c1d4bbf7813a2366be05f08eca3acaeb32a16378f4fc
7
- data.tar.gz: ae84c0e2d70bd24e514030381c23ccefc6732112fee86053a70f8ecb4f20ec3c51bf8f5f2d7776845e7f6029298995835f08312f2de1c689c298212637bd5db5
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 {} if object.nil?
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(item, with_associations: false)
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
- @query = @query.includes(@projection.relations.keys.map(&:to_sym))
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
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceActiveRecord
2
- VERSION = "1.0.0-beta.58"
2
+ VERSION = "1.0.0-beta.60"
3
3
  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.58
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-06-25 00:00:00.000000000 Z
12
+ date: 2024-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord