forest_admin_datasource_active_record 1.40.0 → 1.40.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: 900ccccbc0c8a7ae95c5eee13a67dca16bbad7add14ac849381a95246878393d
4
- data.tar.gz: 7fb49021e33e83ed9cb8e01a39a813b4e261fae73e8d6d32e936092f843e7aad
3
+ metadata.gz: b924a7fc6ab865fa83285d4dc554e0d2124b26c2b998d6c06c3dcfcd357d313d
4
+ data.tar.gz: dfd941d070ddb69f934b43db627d83ed0dac8af12fcf3dbf5f6594bdfaae617d
5
5
  SHA512:
6
- metadata.gz: dcda7837f4a0d0b6658c10ae3245d9e31ab3933d7302b414e7560716f1cf6ccfb261f4ccc1e93dac131384cfb927cca9b5cb412c6ebace19cff563b24398d67b
7
- data.tar.gz: 43d723551915aace679d91971d5264f70e91f2adbd4a5bde9bc153884a69364292d5fbb7d33e2584794ca5f7009358ee783cdf930b2521035e5ef12e31b70f63
6
+ metadata.gz: 13177d23d5702e9a93d282e09c213c8b99fb2d5ba47828712e3fc67b84a198e67bf65848af806ce58f084c8465bda80ad282c29da73b0413a3e50aac6b38bf0c
7
+ data.tar.gz: 297df24c7a0e70780552f7f0b4712860171930f57cce1c0a7a602732e73ace9ce187e41dde2e8e9048c5796c7674b8a23dd077895bcb05b64cdb96de6e4bc456
@@ -114,6 +114,15 @@ module ForestAdminDatasourceActiveRecord
114
114
  association.source_reflection&.belongs_to?
115
115
  end
116
116
 
117
+ # Same criterion as unrepresentable_many_to_many?: a composite primary key can arrive as a
118
+ # real Array or already flattened by Rails into a mangled String -- checking column
119
+ # membership catches both forms, plus a custom primary_key pointing at a non-column, all of
120
+ # which would otherwise hit nil.column_type in build_one_to_one_schema (#379).
121
+ def unrepresentable_one_to_one?(association)
122
+ !association.klass.column_names.include?(association.klass.primary_key) ||
123
+ !@model.column_names.include?(@model.primary_key)
124
+ end
125
+
117
126
  def build_many_to_many_field(association, through_reflection, is_polymorphic, source_polymorphic)
118
127
  ForestAdminDatasourceToolkit::Schema::Relations::ManyToManySchema.new(
119
128
  foreign_collection: format_model_name(association.klass.name),
@@ -157,15 +166,19 @@ module ForestAdminDatasourceActiveRecord
157
166
 
158
167
  if many_to_many_shape
159
168
  add_many_to_many_field(association, through_reflection, is_polymorphic, source_polymorphic)
169
+ elsif unrepresentable_one_to_one?(association)
170
+ warn_unrepresentable_one_to_one(association, through_reflection)
160
171
  else
161
172
  add_field(
162
173
  association.name.to_s,
163
174
  ForestAdminDatasourceToolkit::Schema::Relations::OneToOneSchema.new(
164
175
  foreign_collection: format_model_name(association.klass.name),
165
176
  origin_key: association.klass.primary_key,
166
- origin_key_target: @model.primary_key
177
+ origin_key_target: @model.primary_key,
178
+ is_read_only: true
167
179
  )
168
180
  )
181
+ warn_readonly_identity_join(association, through_reflection)
169
182
  end
170
183
  elsif association.inverse_of&.polymorphic?
171
184
  add_field(
@@ -362,6 +375,33 @@ module ForestAdminDatasourceActiveRecord
362
375
  )
363
376
  end
364
377
 
378
+ def warn_unrepresentable_one_to_one(association, through_reflection)
379
+ logger = ActiveSupport::Logger.new($stdout)
380
+ logger.warn(
381
+ "[ForestAdmin] ⚠️ Skipping association '#{association.name}' in model '#{@model.name}': " \
382
+ "this has_one :through (via '#{format_model_name(through_reflection.klass.name)}') can't be " \
383
+ 'represented as a Forest Admin one-to-one -- one of its endpoints has a composite primary key.'
384
+ )
385
+ end
386
+
387
+ # OneToOneSchema has no through_collection, so this publishes each side's own primary key
388
+ # as a placeholder join -- the columns exist on both sides, so GeneratorField's field
389
+ # lookups don't raise, but the join isn't meaningful data (it matches two unrelated
390
+ # sequences), which is exactly why it's marked read-only rather than left writable through
391
+ # what's really the foreign collection's own primary key (#379).
392
+ def warn_readonly_identity_join(association, through_reflection)
393
+ logger = ActiveSupport::Logger.new($stdout)
394
+ foreign_key = association.klass.primary_key
395
+ origin_key = @model.primary_key
396
+ logger.warn(
397
+ "[ForestAdmin] ⚠️ Association '#{association.name}' in model '#{@model.name}' is published " \
398
+ "as a read-only one-to-one joining '#{format_model_name(association.klass.name)}'.'#{foreign_key}' " \
399
+ "to this model's own '#{origin_key}': it's a has_one chained through " \
400
+ "'#{format_model_name(through_reflection.klass.name)}', which OneToOneSchema can't express as a " \
401
+ 'real two-hop join -- see #379 for background.'
402
+ )
403
+ end
404
+
365
405
  def warn_missing_polymorphic_columns(association)
366
406
  missing_columns = []
367
407
  missing_columns << association.foreign_key unless schema[:fields][association.foreign_key]
@@ -1,3 +1,3 @@
1
1
  module ForestAdminDatasourceActiveRecord
2
- VERSION = "1.40.0"
2
+ VERSION = "1.40.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.40.0
4
+ version: 1.40.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: 2026-08-27 00:00:00.000000000 Z
12
+ date: 2026-08-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord