forest_admin_datasource_active_record 1.14.0 → 1.14.2

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: 0aca63f1bf2a3ad065e61000b5bba057154c5a7879104a5a5e6e18584bea58e1
4
- data.tar.gz: a46e81981549b569d72c238bc78062d16fc06428c6c8b86198269451e5c2d5c0
3
+ metadata.gz: 4f9af86ad7f57b450c0e780e0df0ff4c6b3d8a76e6974f3e2f05356a8662f9bd
4
+ data.tar.gz: 43e986234e5b73a2feeda31b1d7d5baf38ef868ba1ae0549b4e37f45a2db7d90
5
5
  SHA512:
6
- metadata.gz: 77956a7dad5c4f9825565de6d41c7b624eac2bf8e1c5e6be1d45f3bd646374439cf1ab5ef618985aeba309be27cb5a23139817c4255805b9f1ba29886c10c38f
7
- data.tar.gz: 656be438cd64847bd2c782df16c0eb933dd1ab09eb0281e8e7ccf5b102d0ac8a0e0d9a6f70b7910180057759ef9922a1f97fb0cc45309ecb6bd40a5fe8bc9ade
6
+ metadata.gz: 9fec9e98866cbe2b4e99d87fb39a779f137bce25b4ca63dd9065bf89014172d6f690da77d59890408f9b26f9ba0fc422c725b3daff16857deabced91fec46a5d
7
+ data.tar.gz: c695dba049358d02ca30eae1924841958dc67097370447e2579e7e895e45b592c2629c5657ea70e7f9f11d4f79eb79f07249bcb132623beb4fcfd36528650d22
@@ -80,21 +80,27 @@ module ForestAdminDatasourceActiveRecord
80
80
  association.polymorphic?
81
81
  end
82
82
 
83
+ # rubocop:disable Metrics/BlockNesting
83
84
  def fetch_associations
84
85
  associations(@model, support_polymorphic_relations: @support_polymorphic_relations).each do |association|
85
86
  case association.macro
86
87
  when :has_one
87
88
  if association_primary_key?(association)
88
89
  if association.through_reflection?
90
+ through_reflection = association.through_reflection
91
+ is_polymorphic = through_reflection.options[:as].present?
92
+
89
93
  add_field(
90
94
  association.name.to_s,
91
95
  ForestAdminDatasourceToolkit::Schema::Relations::ManyToManySchema.new(
92
96
  foreign_collection: format_model_name(association.klass.name),
93
- origin_key: association.through_reflection.foreign_key,
94
- origin_key_target: association.through_reflection.join_foreign_key,
97
+ origin_key: through_reflection.foreign_key,
98
+ origin_key_target: through_reflection.join_foreign_key,
95
99
  foreign_key: association.join_foreign_key,
96
100
  foreign_key_target: association.association_primary_key,
97
- through_collection: format_model_name(association.through_reflection.klass.name)
101
+ through_collection: format_model_name(through_reflection.klass.name),
102
+ origin_type_field: is_polymorphic ? through_reflection.type : nil,
103
+ origin_type_value: is_polymorphic ? @model.name : nil
98
104
  )
99
105
  )
100
106
  elsif association.inverse_of&.polymorphic?
@@ -151,15 +157,20 @@ module ForestAdminDatasourceActiveRecord
151
157
  when :has_many
152
158
  if association_primary_key?(association)
153
159
  if association.through_reflection?
160
+ through_reflection = association.through_reflection
161
+ is_polymorphic = through_reflection.options[:as].present?
162
+
154
163
  add_field(
155
164
  association.name.to_s,
156
165
  ForestAdminDatasourceToolkit::Schema::Relations::ManyToManySchema.new(
157
166
  foreign_collection: format_model_name(association.klass.name),
158
- origin_key: association.through_reflection.foreign_key,
159
- origin_key_target: association.through_reflection.join_foreign_key,
167
+ origin_key: through_reflection.foreign_key,
168
+ origin_key_target: through_reflection.join_foreign_key,
160
169
  foreign_key: association.join_foreign_key,
161
170
  foreign_key_target: association.association_primary_key,
162
- through_collection: format_model_name(association.through_reflection.klass.name)
171
+ through_collection: format_model_name(through_reflection.klass.name),
172
+ origin_type_field: is_polymorphic ? through_reflection.type : nil,
173
+ origin_type_value: is_polymorphic ? @model.name : nil
163
174
  )
164
175
  )
165
176
  elsif association.inverse_of&.polymorphic?
@@ -197,8 +208,15 @@ module ForestAdminDatasourceActiveRecord
197
208
  )
198
209
  )
199
210
  end
211
+ rescue StandardError => e
212
+ logger = ActiveSupport::Logger.new($stdout)
213
+ logger.warn(
214
+ "[ForestAdmin] Unable to process association '#{association.name}' " \
215
+ "in model '#{@model.name}': #{e.message}. Skipping this association."
216
+ )
200
217
  end
201
218
  end
219
+ # rubocop:enable Metrics/BlockNesting
202
220
 
203
221
  def warn_missing_polymorphic_columns(association)
204
222
  missing_columns = []
@@ -15,6 +15,8 @@ module ForestAdminDatasourceActiveRecord
15
15
  def polymorphic?(association)
16
16
  (association.options.key?(:polymorphic) && association.options[:polymorphic]) ||
17
17
  association.inverse_of&.polymorphic?
18
+ rescue StandardError
19
+ false
18
20
  end
19
21
 
20
22
  def get_class(association)
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceActiveRecord
2
- VERSION = "1.14.0"
2
+ VERSION = "1.14.2"
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.14.0
4
+ version: 1.14.2
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-07 00:00:00.000000000 Z
12
+ date: 2025-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord