forest_liana 9.17.2 → 9.17.4

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: 44ec79f4e42ec91b8c5306d87672aab03a6b30072e88e27fdcb311d3d7d2c8de
4
- data.tar.gz: e5f37934ccdbf40a78499fd22fcafcd037b8eed1b12034c773bbb499d16b60c7
3
+ metadata.gz: b7a86f85b47098ca555b8f032bec32c813acc38ab3f3c4a1195d144d3a87aed1
4
+ data.tar.gz: 658e86bf9a50f4301de598982879ef511b022901f1f2841c48d6e244efb4dbd5
5
5
  SHA512:
6
- metadata.gz: 93d789834be64fe90cdc9b58c8201df5b75396d627a1138ec1d46e437cfb60d7d63246ece332db3890a6a0cb5eb672683655abc5736dc5c85d38ab2aea47e41a
7
- data.tar.gz: 91b3c9bf5856f4b628ca31b4140bab3f00b96bd3a7afe670cefaa8701499a86e2fca9e0c431b7a621c86283bae0eefa13afb5104f25ad89589105eb007fa34b9
6
+ metadata.gz: 87b9319960622c67bf4bbea12e4a31447daf30e640a6d85c259dc857a3acec043edbb34b10cccd676d8a050e00068e343ba778e550c79821967ae78885d39360
7
+ data.tar.gz: 60a672c6dd59c250d973a4afd9e1738650106eab342f1af3a260ce6437e660e1e87a20613252bd0d826cec1bb262bbf3bc6dc2822e1db42aadfc237d075d5f36
@@ -343,23 +343,44 @@ module ForestLiana
343
343
  association = get_one_association(path)
344
344
  if association
345
345
  through_chain = []
346
- while association.options[:through]
347
- through_chain << association.options[:through]
348
- association = get_one_association(association.options[:through])
346
+ current_association = association
347
+ while current_association.options[:through]
348
+ through_chain << current_association.options[:through]
349
+ current_association = get_one_association(current_association.options[:through])
349
350
  end
350
351
 
351
352
  # Skip ActiveStorage associations - already processed above
352
353
  next if is_active_storage_association?(association)
353
354
 
354
- # For :through associations, only add foreign keys from the direct (first) association in the chain
355
- # Don't try to select columns from the main table for the final :through target
355
+ # For :through associations, recursively add all intermediate foreign keys
356
356
  if through_chain.any?
357
- # Use the first association in the through chain
358
- first_through = get_one_association(through_chain.first)
359
- if first_through && (first_through.macro == :belongs_to || first_through.macro == :has_one)
360
- foreign_keys = Array(first_through.foreign_key)
361
- foreign_keys.each do |fk|
362
- select << "#{@resource.table_name}.#{fk}"
357
+ current_resource = @resource
358
+ through_chain.reverse.each do |through_name|
359
+ through_assoc = current_resource.reflect_on_association(through_name)
360
+
361
+ if through_assoc
362
+ if through_assoc.options[:through]
363
+ direct_through_name = through_assoc.options[:through]
364
+ direct_assoc = current_resource.reflect_on_association(direct_through_name)
365
+
366
+ if direct_assoc && (direct_assoc.macro == :belongs_to || direct_assoc.macro == :has_one)
367
+ fks = Array(direct_assoc.foreign_key)
368
+ fks.each do |fk|
369
+ select << "#{current_resource.table_name}.#{fk}"
370
+ end
371
+ end
372
+ else
373
+ # Direct association (not nested through)
374
+ if through_assoc.macro == :belongs_to || through_assoc.macro == :has_one
375
+ fks = Array(through_assoc.foreign_key)
376
+ fks.each do |fk|
377
+ select << "#{current_resource.table_name}.#{fk}"
378
+ end
379
+ end
380
+ end
381
+
382
+ # Move to the next level in the chain
383
+ current_resource = through_assoc.klass if through_assoc.klass
363
384
  end
364
385
  end
365
386
  else
@@ -369,8 +390,8 @@ module ForestLiana
369
390
  end
370
391
 
371
392
  if association.macro == :belongs_to || association.macro == :has_one
372
- foreign_keys = Array(association.foreign_key)
373
- foreign_keys.each do |fk|
393
+ fks = Array(association.foreign_key)
394
+ fks.each do |fk|
374
395
  select << "#{@resource.table_name}.#{fk}"
375
396
  end
376
397
  end
@@ -394,7 +415,11 @@ module ForestLiana
394
415
  end
395
416
  end
396
417
  else
397
- select << "#{@resource.table_name}.#{path}"
418
+ # Only add as column if it's not an association
419
+ # Associations are handled by the through chain logic above
420
+ unless association
421
+ select << "#{@resource.table_name}.#{path}"
422
+ end
398
423
  end
399
424
  end
400
425
 
@@ -75,7 +75,11 @@ module ForestLiana
75
75
  end
76
76
  # NOTICE: Rails 3 do not have a defined_enums method
77
77
  elsif REGEX_UUID.match(@search) && column.type == :uuid
78
- conditions << "#{column_name} = :search_value_for_uuid"
78
+ if column.respond_to?(:array) && column.array
79
+ conditions << ":search_value_for_uuid = ANY(#{column_name})"
80
+ else
81
+ conditions << "#{column_name} = :search_value_for_uuid"
82
+ end
79
83
  elsif @resource.respond_to?(:defined_enums) &&
80
84
  @resource.defined_enums.has_key?(column.name) &&
81
85
  !@resource.defined_enums[column.name][@search.downcase].nil?
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "9.17.2"
2
+ VERSION = "9.17.4"
3
3
  end
@@ -0,0 +1,48 @@
1
+ module ForestLiana
2
+ describe SearchQueryBuilder do
3
+ let(:user) { { 'id' => '1', 'rendering_id' => 1 } }
4
+ let(:collection) { ForestLiana::Model::Collection.new(name: 'Tree', fields: []) }
5
+ let(:search_uuid) { '75fbcb43-f6f8-4cd1-861f-09a61fd1ddad' }
6
+ let(:params) { { search: search_uuid, searchExtended: '0' } }
7
+ let(:builder) { described_class.new(params, [], collection, user) }
8
+
9
+ before do
10
+ allow(ForestLiana::ScopeManager)
11
+ .to receive(:append_scope_for_user)
12
+ .and_return(nil)
13
+ allow(ForestLiana)
14
+ .to receive(:schema_for_resource)
15
+ .and_return(ForestLiana::Model::Collection.new(name: 'Tree', fields: []))
16
+ end
17
+
18
+ describe '#perform' do
19
+ context 'when a column is an array uuid type' do
20
+ let(:array_uuid_column) do
21
+ double('Column', name: 'attachment_ids', type: :uuid, array: true).tap do |col|
22
+ allow(col).to receive(:respond_to?).with(:array).and_return(true)
23
+ end
24
+ end
25
+
26
+ let(:normal_uuid_column) do
27
+ double('Column', name: 'external_id', type: :uuid, array: false).tap do |col|
28
+ allow(col).to receive(:respond_to?).with(:array).and_return(true)
29
+ end
30
+ end
31
+
32
+ before do
33
+ allow(Tree).to receive(:columns).and_return([array_uuid_column, normal_uuid_column])
34
+ end
35
+
36
+ it 'searches the array column using ANY() syntax' do
37
+ result = builder.perform(Tree.all)
38
+ expect(result.to_sql).to match(/= ANY.*attachment_ids/i)
39
+ end
40
+
41
+ it 'searches the non-array uuid column using equality syntax' do
42
+ result = builder.perform(Tree.all)
43
+ expect(result.to_sql).to match(/"external_id"\s+=\s+'#{search_uuid}'/i)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
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.2
4
+ version: 9.17.4
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-01-20 00:00:00.000000000 Z
11
+ date: 2026-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -465,6 +465,7 @@ files:
465
465
  - spec/services/forest_liana/schema_adapter_default_values_spec.rb
466
466
  - spec/services/forest_liana/schema_adapter_spec.rb
467
467
  - spec/services/forest_liana/scope_manager_spec.rb
468
+ - spec/services/forest_liana/search_query_builder_spec.rb
468
469
  - spec/services/forest_liana/serializer_factory_spec.rb
469
470
  - spec/services/forest_liana/smart_action_field_validator_spec.rb
470
471
  - spec/services/forest_liana/smart_action_form_parser_spec.rb
@@ -775,6 +776,7 @@ test_files:
775
776
  - spec/services/forest_liana/schema_adapter_default_values_spec.rb
776
777
  - spec/services/forest_liana/schema_adapter_spec.rb
777
778
  - spec/services/forest_liana/scope_manager_spec.rb
779
+ - spec/services/forest_liana/search_query_builder_spec.rb
778
780
  - spec/services/forest_liana/serializer_factory_spec.rb
779
781
  - spec/services/forest_liana/smart_action_field_validator_spec.rb
780
782
  - spec/services/forest_liana/smart_action_form_parser_spec.rb