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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2104fd819189def35b7af7020d3823449a4db8b302269795f02092dca19e0f5d
|
|
4
|
+
data.tar.gz: e6f0a55c825a3087db733b7fbde74e88444771c28add933e4a336fbb416cf692
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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:
|
|
94
|
-
origin_key_target:
|
|
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(
|
|
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:
|
|
159
|
-
origin_key_target:
|
|
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(
|
|
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 = []
|