forest_liana 9.17.5 → 9.17.6

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: 4610a65fec1c6400f4f8b4b904892d23a4e842d5aefac4fed38257abc8cadec4
4
- data.tar.gz: e5ce8d49d0eded514f8222b3bfe1d69ed70e9cc10a7db8062e63181ed9a400ca
3
+ metadata.gz: 9b410ae815afe1b2592a38ab27cb5133198fb76b4624dee5217cdb2c65583a74
4
+ data.tar.gz: 2527c8944450bd5348962ef65dea48c6e7e1f1bf434e409bdbb26591d93d03c9
5
5
  SHA512:
6
- metadata.gz: f6cef35e4621ca4667021e98c4cc0072ff7309095500a2ee5b76ce82a46a6aee1d95166eb3be33154f80eee51360649d6885dc38ec2cda6fc88afeaf70d26b04
7
- data.tar.gz: 46d6f1cca8c6e5ac467954efc9ab5ae57a0ef2300cd3508639d98e8ca24d366b499fb97ef25523f12e288ba19a2dff92360ac6b12acfb9782814d4545948ea37
6
+ metadata.gz: 87d6d1e526ae2ea81c8eb5f0f4d557ae0cf65e406708cea7d998455f54d7eeee9bf9667efb6637e71b1a5deb4b084fc1fdd1dacb936499b00ab3bdcfdaec9178
7
+ data.tar.gz: fc0ee5ba0847140d5830715b861ccab6fe273fa7ea7c5f63ade342fa85645823c77ba51e91e2ef746dd5343c9a65e1d4012bf699fb6990e8b12dcdc344ac18db
@@ -37,6 +37,7 @@ class ForestLiana::Model::Collection
37
37
  field[:enums] = nil unless field.key?(:enums)
38
38
  field[:integration] = nil unless field.key?(:integration)
39
39
  field[:is_filterable] = true unless field.key?(:is_filterable)
40
+ field[:is_primary_key] = false unless field.key?(:is_primary_key)
40
41
  field[:is_read_only] = false unless field.key?(:is_read_only)
41
42
  field[:is_required] = false unless field.key?(:is_required)
42
43
  field[:is_sortable] = true unless field.key?(:is_sortable)
@@ -20,6 +20,7 @@ module ForestLiana
20
20
  'enums',
21
21
  'integration',
22
22
  'is_filterable',
23
+ 'is_primary_key',
23
24
  'is_read_only',
24
25
  'is_required',
25
26
  'is_sortable',
@@ -248,6 +248,7 @@ module ForestLiana
248
248
  relationship: get_relationship_type(association),
249
249
  reference: "#{association.name.to_s}.id",
250
250
  inverse_of: @model.name.demodulize.underscore,
251
+ is_primary_key: false,
251
252
  is_filterable: false,
252
253
  is_sortable: true,
253
254
  is_read_only: false,
@@ -278,6 +279,7 @@ module ForestLiana
278
279
  field[:field] = association.name
279
280
  field[:inverse_of] = inverse_of(association)
280
281
  field[:relationship] = get_relationship_type(association)
282
+ field[:is_primary_key] = false
281
283
 
282
284
  ForestLiana::SchemaUtils.disable_filter_and_sort_if_cross_db!(
283
285
  field,
@@ -332,6 +334,7 @@ module ForestLiana
332
334
  schema = {
333
335
  field: column.name,
334
336
  type: column_type,
337
+ is_primary_key: primary_key?(column),
335
338
  is_filterable: true,
336
339
  is_sortable: true,
337
340
  is_read_only: false,
@@ -351,6 +354,16 @@ module ForestLiana
351
354
  add_validations(schema, column)
352
355
  end
353
356
 
357
+ def primary_key?(column)
358
+ pk = @model.primary_key
359
+ if pk.is_a?(Array)
360
+ # NOTICE: composite_primary_keys exposes an Array of column names.
361
+ pk.map(&:to_s).include?(column.name)
362
+ else
363
+ !pk.nil? && pk.to_s == column.name
364
+ end
365
+ end
366
+
354
367
  def get_schema_for_association(association)
355
368
  opts ={
356
369
  field: association.name.to_s,
@@ -358,6 +371,7 @@ module ForestLiana
358
371
  relationship: get_relationship_type(association),
359
372
  reference: "#{ForestLiana.name_for(association.klass)}.id",
360
373
  inverse_of: inverse_of(association),
374
+ is_primary_key: false,
361
375
  is_filterable: !is_many_association(association),
362
376
  is_sortable: true,
363
377
  is_read_only: false,
@@ -68,6 +68,7 @@ module ForestLiana::Collection
68
68
  opts[:is_read_only] = true unless opts.has_key?(:is_read_only)
69
69
  opts[:is_read_only] = false if opts.has_key?(:set)
70
70
  opts[:is_required] = false unless opts.has_key?(:is_required)
71
+ opts[:is_primary_key] = false unless opts.has_key?(:is_primary_key)
71
72
  opts[:type] = "String" unless opts.has_key?(:type)
72
73
  opts[:default_value] = nil unless opts.has_key?(:default_value)
73
74
  opts[:integration] = nil unless opts.has_key?(:integration)
@@ -26,6 +26,7 @@ module ForestLiana
26
26
  'enums',
27
27
  'integration',
28
28
  'is_filterable',
29
+ 'is_primary_key',
29
30
  'is_read_only',
30
31
  'is_required',
31
32
  'is_sortable',
@@ -86,6 +87,7 @@ module ForestLiana
86
87
  field['enums'] = nil unless field.has_key?('enums')
87
88
  field['integration'] = nil unless field.has_key?('integration')
88
89
  field['is_filterable'] = false unless field.has_key?('is_filterable')
90
+ field['is_primary_key'] = false unless field.has_key?('is_primary_key')
89
91
  field['is_read_only'] = true unless field.has_key?('is_read_only')
90
92
  field['is_required'] = false unless field.has_key?('is_required')
91
93
  field['is_sortable'] = false unless field.has_key?('is_sortable')
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.17.5"
2
+ VERSION = "9.17.6"
3
3
  end
@@ -25,6 +25,7 @@ module ForestLiana
25
25
  validations: [],
26
26
  is_virtual: true,
27
27
  field: :address_type,
28
+ is_primary_key: false,
28
29
  is_filterable: false,
29
30
  is_sortable: false
30
31
  }
@@ -15,6 +15,7 @@ module ForestLiana
15
15
  relationship: "BelongsTo",
16
16
  reference: "addressable.id",
17
17
  inverse_of: "address",
18
+ is_primary_key: false,
18
19
  is_filterable: false,
19
20
  is_sortable: true,
20
21
  is_read_only: false,
@@ -36,6 +36,39 @@ module ForestLiana
36
36
  assert fields.size == 1
37
37
  end
38
38
 
39
+ test 'the standard primary key column is flagged is_primary_key: true' do
40
+ adapter = SchemaAdapter.new(IntegerField)
41
+ schema = adapter.send(:get_schema_for_column, IntegerField.columns_hash['id'])
42
+ assert_equal true, schema[:is_primary_key]
43
+ end
44
+
45
+ test 'a non primary key column is flagged is_primary_key: false' do
46
+ adapter = SchemaAdapter.new(IntegerField)
47
+ schema = adapter.send(:get_schema_for_column, IntegerField.columns_hash['field'])
48
+ assert_equal false, schema[:is_primary_key]
49
+ end
50
+
51
+ test 'every column of a composite primary key is flagged is_primary_key: true' do
52
+ adapter = SchemaAdapter.new(BelongsToField)
53
+ BelongsToField.define_singleton_method(:primary_key) { ['id', 'has_one_field_id'] }
54
+ is_pk = ->(name) do
55
+ adapter.send(:get_schema_for_column, BelongsToField.columns_hash[name])[:is_primary_key]
56
+ end
57
+
58
+ assert_equal true, is_pk.call('id')
59
+ assert_equal true, is_pk.call('has_one_field_id')
60
+ assert_equal false, is_pk.call('has_many_field_id')
61
+ ensure
62
+ BelongsToField.singleton_class.send(:remove_method, :primary_key)
63
+ end
64
+
65
+ test 'an association is flagged is_primary_key: false' do
66
+ adapter = SchemaAdapter.new(HasOneField)
67
+ association = HasOneField.reflect_on_association(:belongs_to_field)
68
+ schema = adapter.send(:get_schema_for_association, association)
69
+ assert_equal false, schema[:is_primary_key]
70
+ end
71
+
39
72
  test 'belongsTo relationship' do
40
73
  schema = SchemaAdapter.new(BelongsToField).perform
41
74
  fields = schema.fields.select do |field|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.17.5
4
+ version: 9.17.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-29 00:00:00.000000000 Z
11
+ date: 2026-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails