forest_admin_datasource_active_record 1.0.0.pre.beta.59 → 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: fc828978458b7c1566d7f61d007df24401281c115bc54a551fbedde6e6cf3783
4
- data.tar.gz: 3fbea7107c9ffbb8442f01b47fc58bb23bccf47513e34d6b7caec47516098742
3
+ metadata.gz: 06eb4e50d70ed020e78c247129d24f1a514efcc8e3150864ac00e2a420d715ed
4
+ data.tar.gz: e11b2afab09fbf5ac3e9555a288f70638e2c01e5d2135a983b8601324d701916
5
5
  SHA512:
6
- metadata.gz: 0ec4a0787f25fc01d5de4a3afaa320962bdb78716d5db67e05fc195d30eacf386b9f4ea571e57e7fd663415727b2ed75c84d4bf2f05486b7286d9bb4d2a66f5a
7
- data.tar.gz: 4b201a38b1543eb8a528eab862e653ca5316173c841b426024b5de56632920a7cec966e5687914b8108d261d906920a3a9b1d990996318ba8ed1c28fe2184437
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.59"
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.59
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-07-01 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