forest_admin_datasource_toolkit 1.0.0.pre.beta.64 → 1.0.0.pre.beta.65

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: 05b86e9f739a36be76766d3d56f0162ee04809942091078fa60948603fadc428
4
- data.tar.gz: 51256c9a0118701bd433c4ed2a83c6e41655db9ee0edfcbc58cc9ccf0242e5cb
3
+ metadata.gz: fd5e11bf75b0839e35d3f44e6502e76785c5b4d376cb94d128d877d49030e365
4
+ data.tar.gz: ff66ca88263adb91efbb6a2f254893f4274a779ba062bc865ec06b9756790f84
5
5
  SHA512:
6
- metadata.gz: a3db9f7c20db3ce087aa8fc693e4a1b30007f88c1e4bcb813e4e75962218b7b59ee9c55d14661182d1ec8e59b04faf90fe7bc1b4fc28279c05e950df2a63e89f
7
- data.tar.gz: fd2cb508b67f6f39ba14ef798fea7a8d640e793e917bd83745e09dbfd169a6045c24136e301a98c86d27cd8b15b088bbabe23666128e7f175806a0d4510cea7b
6
+ metadata.gz: 1229b9e6453ecc3ad4ace3869c252a01a2fd19227c0b603369de3a3e6e834990a8357a0c20ca32d733baa7b79b2f9ceb3a1cdc47d03a5e5299b1d9cd43e213b7
7
+ data.tar.gz: cd6dab546b51a50ee21a7ae62d15cbeab11075625e9e1e7d146ff55a6592877557faf67705aca60884277255fb766d0cf06fadc0435219f6adbcb4eb5e6ef94f
@@ -14,6 +14,8 @@ module ForestAdminDatasourceToolkit
14
14
  inverse = foreign_collection.schema[:fields].select do |_name, field|
15
15
  if polymorphic_relations.include?(relation_field.type)
16
16
  field.is_a?(PolymorphicManyToOneSchema) &&
17
+ field.foreign_key_type_field == relation_field.origin_type_field &&
18
+ field.foreign_key == relation_field.origin_key &&
17
19
  field.foreign_collections.include?(collection.name)
18
20
  else
19
21
  field.is_a?(RelationSchema) &&
@@ -22,19 +22,26 @@ module ForestAdminDatasourceToolkit
22
22
  end
23
23
  end
24
24
  else
25
- prefix = field[0, dot_index]
25
+ prefix, suffix = field.split(':')
26
26
  schema = collection.schema[:fields][prefix]
27
27
 
28
28
  raise Exceptions::ValidationError, "Relation not found: '#{collection.name}.#{prefix}'" if schema.nil?
29
29
 
30
- if schema.type != 'ManyToOne' && schema.type != 'OneToOne'
30
+ if schema.type == 'PolymorphicManyToOne' && suffix != '*'
31
+ raise Exceptions::ValidationError, "Unexpected nested field #{suffix} under generic relation: #{collection.name}.#{prefix}"
32
+ end
33
+
34
+ if schema.type != 'ManyToOne' && schema.type != 'OneToOne' && schema.type != 'PolymorphicManyToOne' &&
35
+ schema.type != 'PolymorphicOneToOne'
31
36
  raise Exceptions::ValidationError,
32
- "Unexpected field type: '#{collection.name}.#{prefix}' (found '#{schema.type}' expected 'ManyToOne' or 'OneToOne')"
37
+ "Unexpected field type: '#{collection.name}.#{prefix}' (found '#{schema.type}')"
33
38
  end
34
39
 
35
- suffix = field[dot_index + 1, field.length - dot_index - 1]
36
- association = collection.datasource.get_collection(schema.foreign_collection)
37
- validate(association, suffix, values)
40
+ if schema.type != 'PolymorphicManyToOne'
41
+ suffix = field[dot_index + 1, field.length - dot_index - 1]
42
+ association = collection.datasource.get_collection(schema.foreign_collection)
43
+ validate(association, suffix, values)
44
+ end
38
45
  end
39
46
  end
40
47
 
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceToolkit
2
- VERSION = "1.0.0-beta.64"
2
+ VERSION = "1.0.0-beta.65"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_admin_datasource_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.64
4
+ version: 1.0.0.pre.beta.65
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-08-21 00:00:00.000000000 Z
12
+ date: 2024-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport