forest_admin_datasource_toolkit 1.13.4 → 1.14.1

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: b67c52dca2273ac1d0ac79fbd5afc1de901b0ee9bd69f97810796358c14c303d
4
- data.tar.gz: 37c176c78e94070a4f0eaba728c0b257364839beed0b873965c713bc4c5c8341
3
+ metadata.gz: 6f0442b4f60efa1772ca6ea224ce5af2137ce0c59aca42a8c68b571bda10cd9c
4
+ data.tar.gz: cc83253fa699a7423af947e194b91a510d1772e19450ff02c001cf6d8f7334da
5
5
  SHA512:
6
- metadata.gz: 01d6e4d7213d22dee58fa3931df14d9bac7f7a2cdac54fb4bc9454127390ad2b2645db7009861056c48519bc07f4f5d57dc656887bed6d215423e984ae921959
7
- data.tar.gz: e29db840ff87e5bd5edb6720b7db3d9e2282c666233fc552295b48cd76e48be490767bd71ee26b5b83d0a8ba7b022fbe0c33d062c05f5033a6fc4106b7400757
6
+ metadata.gz: aae976cc55a84863c2277b30934a9c302821be6638e1c1cdacfe4a46c37e79e1208b03a1f4cf90dd6a681258d4ff22525c89688d50701e139ee9b1eff060d110
7
+ data.tar.gz: b5a59884fece3213995da019302b59c6a2702abd73b46c0afa48c0697ff04c16f6511ef5716b424ab12b55695b9b8fcf6309c9d29362a7cfafe95ecb5632c14c
@@ -89,12 +89,15 @@ module ForestAdminDatasourceToolkit
89
89
  )
90
90
  else
91
91
  through_collection = collection.datasource.get_collection(relation.through_collection)
92
- through_tree = ConditionTreeFactory.intersect(
93
- [
94
- Nodes::ConditionTreeLeaf.new(relation.origin_key, Operators::EQUAL, origin_value),
95
- Nodes::ConditionTreeLeaf.new(relation.foreign_key, Operators::PRESENT)
96
- ]
97
- )
92
+ conditions = [
93
+ Nodes::ConditionTreeLeaf.new(relation.origin_key, Operators::EQUAL, origin_value),
94
+ Nodes::ConditionTreeLeaf.new(relation.foreign_key, Operators::PRESENT)
95
+ ]
96
+
97
+ # add polymorphic type condition if the through association is polymorphic
98
+ add_polymorphic_condition(conditions, relation)
99
+
100
+ through_tree = ConditionTreeFactory.intersect(conditions)
98
101
  records = through_collection.list(
99
102
  caller,
100
103
  Filter.new(condition_tree: through_tree),
@@ -141,12 +144,16 @@ module ForestAdminDatasourceToolkit
141
144
  if foreign_relation && base_foreign_filter.nestable?
142
145
  foreign_key = collection.datasource.get_collection(relation.through_collection).schema[:fields][relation.foreign_key]
143
146
  base_through_filter = base_foreign_filter.nest(foreign_relation)
144
- condition_tree = ConditionTreeFactory.intersect(
145
- [
146
- Nodes::ConditionTreeLeaf.new(relation.origin_key, Operators::EQUAL, origin_value),
147
- base_through_filter.condition_tree
148
- ]
149
- )
147
+
148
+ conditions = [
149
+ Nodes::ConditionTreeLeaf.new(relation.origin_key, Operators::EQUAL, origin_value),
150
+ base_through_filter.condition_tree
151
+ ]
152
+
153
+ # add polymorphic type condition if the through association is polymorphic
154
+ add_polymorphic_condition(conditions, relation)
155
+
156
+ condition_tree = ConditionTreeFactory.intersect(conditions)
150
157
 
151
158
  if foreign_key.type == 'Column' && foreign_key.filter_operators.include?(Operators::PRESENT)
152
159
  present = Nodes::ConditionTreeLeaf.new(relation.foreign_key, Operators::PRESENT)
@@ -165,20 +172,33 @@ module ForestAdminDatasourceToolkit
165
172
  Projection.new([relation.foreign_key_target])
166
173
  )
167
174
 
168
- Filter.new(
169
- condition_tree: ConditionTreeFactory.intersect(
170
- [
171
- # only children of parent
172
- Nodes::ConditionTreeLeaf.new(relation.origin_key, Operators::EQUAL, origin_value),
175
+ conditions = [
176
+ # only children of parent
177
+ Nodes::ConditionTreeLeaf.new(relation.origin_key, Operators::EQUAL, origin_value),
173
178
 
174
- # only the children which match the conditions in baseForeignFilter
175
- Nodes::ConditionTreeLeaf.new(
176
- relation.foreign_key,
177
- Operators::IN,
178
- records.map { |r| r[relation.foreign_key_target] }
179
- )
180
- ]
179
+ # only the children which match the conditions in baseForeignFilter
180
+ Nodes::ConditionTreeLeaf.new(
181
+ relation.foreign_key,
182
+ Operators::IN,
183
+ records.map { |r| r[relation.foreign_key_target] }
181
184
  )
185
+ ]
186
+
187
+ # add polymorphic type condition if the through association is polymorphic
188
+ add_polymorphic_condition(conditions, relation)
189
+
190
+ Filter.new(condition_tree: ConditionTreeFactory.intersect(conditions))
191
+ end
192
+
193
+ def self.add_polymorphic_condition(conditions, relation)
194
+ return conditions unless relation.respond_to?(:origin_type_field) &&
195
+ relation.origin_type_field &&
196
+ relation.origin_type_value
197
+
198
+ conditions << Nodes::ConditionTreeLeaf.new(
199
+ relation.origin_type_field,
200
+ Operators::EQUAL,
201
+ relation.origin_type_value
182
202
  )
183
203
  end
184
204
  end
@@ -2,7 +2,8 @@ module ForestAdminDatasourceToolkit
2
2
  module Schema
3
3
  module Relations
4
4
  class ManyToManySchema < RelationSchema
5
- attr_accessor :origin_key, :through_collection, :foreign_key, :origin_key_target, :foreign_key_target
5
+ attr_accessor :origin_key, :through_collection, :foreign_key, :origin_key_target, :foreign_key_target,
6
+ :origin_type_field, :origin_type_value
6
7
 
7
8
  def initialize(
8
9
  origin_key:,
@@ -10,7 +11,9 @@ module ForestAdminDatasourceToolkit
10
11
  foreign_key:,
11
12
  foreign_key_target:,
12
13
  foreign_collection:,
13
- through_collection:
14
+ through_collection:,
15
+ origin_type_field: nil,
16
+ origin_type_value: nil
14
17
  )
15
18
  super(foreign_collection, 'ManyToMany')
16
19
  @origin_key = origin_key
@@ -18,6 +21,8 @@ module ForestAdminDatasourceToolkit
18
21
  @through_collection = through_collection
19
22
  @foreign_key = foreign_key
20
23
  @foreign_key_target = foreign_key_target
24
+ @origin_type_field = origin_type_field
25
+ @origin_type_value = origin_type_value
21
26
  end
22
27
  end
23
28
  end
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceToolkit
2
- VERSION = "1.13.4"
2
+ VERSION = "1.14.1"
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.13.4
4
+ version: 1.14.1
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-11-06 00:00:00.000000000 Z
12
+ date: 2025-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport