forest_admin_datasource_active_record 1.14.0 → 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: 0aca63f1bf2a3ad065e61000b5bba057154c5a7879104a5a5e6e18584bea58e1
4
- data.tar.gz: a46e81981549b569d72c238bc78062d16fc06428c6c8b86198269451e5c2d5c0
3
+ metadata.gz: 2104fd819189def35b7af7020d3823449a4db8b302269795f02092dca19e0f5d
4
+ data.tar.gz: e6f0a55c825a3087db733b7fbde74e88444771c28add933e4a336fbb416cf692
5
5
  SHA512:
6
- metadata.gz: 77956a7dad5c4f9825565de6d41c7b624eac2bf8e1c5e6be1d45f3bd646374439cf1ab5ef618985aeba309be27cb5a23139817c4255805b9f1ba29886c10c38f
7
- data.tar.gz: 656be438cd64847bd2c782df16c0eb933dd1ab09eb0281e8e7ccf5b102d0ac8a0e0d9a6f70b7910180057759ef9922a1f97fb0cc45309ecb6bd40a5fe8bc9ade
6
+ metadata.gz: c87bc99dfaefdc9939d9afa1d29d183e6fd1369055b09befa2e7302ac235afe80db00ac85315a237ab86434e4225265b198124b7d17eec1886a991373635a09c
7
+ data.tar.gz: 216109fe5d88bc4543d34840350ed540eac3b6f5c0a9b3d4219a3f1f6b34ae8742eee8001da5731310a0967f313d3bbc73a57bfcfee47075539384fa51a67748
@@ -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?
@@ -199,6 +210,7 @@ module ForestAdminDatasourceActiveRecord
199
210
  end
200
211
  end
201
212
  end
213
+ # rubocop:enable Metrics/BlockNesting
202
214
 
203
215
  def warn_missing_polymorphic_columns(association)
204
216
  missing_columns = []
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceActiveRecord
2
- VERSION = "1.14.0"
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_active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu