forest_admin_datasource_active_record 1.11.3 → 1.12.0
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: a40c0defe6cd599ebaa87e949a6336ecb4d52889746fa3ab51fa0bb39be4deb8
|
|
4
|
+
data.tar.gz: 0c42a3bf00e84e2a58d95873aed32297bc199f4de1598b1b6e0287ef6aadfb7c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d9892935ebfced8847e155b0ef0a1c7e145c3ac98ebc0ebf0690e3a1431b63cccfde1cb0269250aa91366c1ed5e85edaa72cd50a7fe06a90984d043b919a9a97
|
|
7
|
+
data.tar.gz: a6eec620c99261ec541373e612ea8b211588a7680915153446604d1a8765146c0bfd1fbb41494e65ced27d7f921ea603774797d6df6ea16c918c40537e72f786
|
|
@@ -12,24 +12,42 @@ module ForestAdminDatasourceActiveRecord
|
|
|
12
12
|
|
|
13
13
|
hash.merge! object.attributes
|
|
14
14
|
|
|
15
|
-
if with_associations
|
|
16
|
-
each_association_collection(object, projection) do |association_name, item|
|
|
17
|
-
hash[association_name] = hash_object(
|
|
18
|
-
item,
|
|
19
|
-
projection.relations[association_name],
|
|
20
|
-
with_associations: projection.relations.key?(association_name)
|
|
21
|
-
)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
15
|
+
serialize_associations(object, projection, hash) if with_associations
|
|
24
16
|
|
|
25
17
|
hash
|
|
26
18
|
end
|
|
27
19
|
|
|
28
|
-
def
|
|
20
|
+
def serialize_associations(object, projection, hash)
|
|
29
21
|
one_associations = %i[has_one belongs_to]
|
|
22
|
+
many_associations = %i[has_many has_and_belongs_to_many]
|
|
23
|
+
|
|
24
|
+
# Handle one-to-one and many-to-one associations
|
|
30
25
|
object.class.reflect_on_all_associations
|
|
31
26
|
.filter { |a| one_associations.include?(a.macro) && projection.relations.key?(a.name.to_s) }
|
|
32
|
-
.each
|
|
27
|
+
.each do |association|
|
|
28
|
+
association_name = association.name.to_s
|
|
29
|
+
hash[association_name] = hash_object(
|
|
30
|
+
object.send(association_name),
|
|
31
|
+
projection.relations[association_name],
|
|
32
|
+
with_associations: projection.relations.key?(association_name)
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Handle one-to-many and many-to-many associations
|
|
37
|
+
object.class.reflect_on_all_associations
|
|
38
|
+
.filter { |a| many_associations.include?(a.macro) && projection.relations.key?(a.name.to_s) }
|
|
39
|
+
.each do |association|
|
|
40
|
+
association_name = association.name.to_s
|
|
41
|
+
collection = object.send(association_name)
|
|
42
|
+
# Serialize the collection as an array
|
|
43
|
+
hash[association_name] = collection.map do |item|
|
|
44
|
+
hash_object(
|
|
45
|
+
item,
|
|
46
|
+
projection.relations[association_name],
|
|
47
|
+
with_associations: projection.relations.key?(association_name)
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
33
51
|
end
|
|
34
52
|
end
|
|
35
53
|
end
|
|
@@ -179,14 +179,16 @@ module ForestAdminDatasourceActiveRecord
|
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
one_to_one_relations = %w[OneToOne PolymorphicOneToOne]
|
|
182
|
+
many_to_one_relations = %w[ManyToOne PolymorphicManyToOne]
|
|
183
|
+
|
|
182
184
|
projection.relations.each do |relation_name, sub_projection|
|
|
183
185
|
relation_schema = collection.schema[:fields][relation_name]
|
|
184
186
|
if collection.model.table_name == @collection.model.table_name
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
if one_to_one_relations.include?(relation_schema.type)
|
|
188
|
+
@select << "#{collection.model.table_name}.#{relation_schema.origin_key_target}"
|
|
189
|
+
elsif many_to_one_relations.include?(relation_schema.type)
|
|
190
|
+
@select << "#{collection.model.table_name}.#{relation_schema.foreign_key}"
|
|
191
|
+
end
|
|
190
192
|
end
|
|
191
193
|
|
|
192
194
|
next if relation_schema.type == 'PolymorphicManyToOne'
|
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.
|
|
4
|
+
version: 1.12.0
|
|
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: 2025-10-
|
|
12
|
+
date: 2025-10-23 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activerecord
|