forest_liana 9.14.1 → 9.14.2
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: a594bcf7830da0f415fbfadfa90d985e46814d07cda6892f317f1834db731ce3
|
4
|
+
data.tar.gz: a565c34a7ef4c7b6e637818963a76b11d772cd716b3eed1db7ffe6b4e8711d2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c12bd80a362e62935a333d6c9b3df3e8bee0618cb29ef3f0a3677d50b4a33b79a66a09e42b38b3ca2a72cb15c2fdef5542d08a4b190f03ce270ed35ce0d951e4
|
7
|
+
data.tar.gz: f0a9ea3a170fff1bab99b583d7c5cc491740ffec9b8f48f6de8eee29bc497c77a7d28db34f49b53e08ee49957a3601c4b37be074a4f2a9a7ee1e427fca5df5a8
|
@@ -47,6 +47,8 @@ module ForestLiana
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def separate_database?(resource, association)
|
50
|
+
return false if SchemaUtils.polymorphic?(association)
|
51
|
+
|
50
52
|
target_model_connection = association.klass.connection
|
51
53
|
target_model_database = target_model_connection.current_database if target_model_connection.respond_to? :current_database
|
52
54
|
resource_connection = resource.connection
|
@@ -58,7 +58,7 @@ module ForestLiana
|
|
58
58
|
records = @records.offset(offset).limit(limit).to_a
|
59
59
|
polymorphic_association, preload_loads = analyze_associations(@resource)
|
60
60
|
|
61
|
-
if polymorphic_association && Rails::VERSION::MAJOR >= 7
|
61
|
+
if polymorphic_association.any? && Rails::VERSION::MAJOR >= 7
|
62
62
|
preloader = ActiveRecord::Associations::Preloader.new(records: records, associations: polymorphic_association)
|
63
63
|
preloader.loaders
|
64
64
|
preloader.branches.each do |branch|
|
@@ -85,7 +85,6 @@ module ForestLiana
|
|
85
85
|
next unless separate_database?(@resource, association)
|
86
86
|
|
87
87
|
columns = columns_for_cross_database_association(association_name)
|
88
|
-
|
89
88
|
if association.macro == :belongs_to
|
90
89
|
foreign_key = association.foreign_key
|
91
90
|
primary_key = association.klass.primary_key
|
@@ -125,27 +124,22 @@ module ForestLiana
|
|
125
124
|
end
|
126
125
|
|
127
126
|
def columns_for_cross_database_association(association_name)
|
128
|
-
return [:id] unless @params[:fields].present?
|
129
|
-
|
130
|
-
fields = @params[:fields][association_name.to_s]
|
131
|
-
return [:id] unless fields
|
132
|
-
|
133
|
-
base_fields = fields.split(',').map(&:strip).map(&:to_sym) | [:id]
|
134
|
-
|
135
127
|
association = @resource.reflect_on_association(association_name)
|
136
|
-
extra_key = association.foreign_key
|
137
128
|
|
138
|
-
#
|
139
|
-
|
140
|
-
|
129
|
+
# Always include all columns of the associated model to avoid missing attribute errors
|
130
|
+
columns = association.klass.column_names.map(&:to_sym)
|
131
|
+
|
132
|
+
# Ensure the foreign key is present for manual binding (especially for has_one)
|
133
|
+
columns << association.foreign_key.to_sym if association.macro == :has_one
|
141
134
|
|
142
|
-
|
135
|
+
columns.uniq
|
143
136
|
end
|
144
137
|
|
145
138
|
def compute_includes
|
146
139
|
associations_has_one = ForestLiana::QueryHelper.get_one_associations(@resource)
|
140
|
+
|
147
141
|
@optional_includes = []
|
148
|
-
if @field_names_requested
|
142
|
+
if @field_names_requested && @params['searchExtended'].to_i != 1
|
149
143
|
includes = associations_has_one.map do |association|
|
150
144
|
association_name = association.name.to_s
|
151
145
|
|
@@ -175,7 +169,10 @@ module ForestLiana
|
|
175
169
|
|
176
170
|
@includes = (includes & @field_names_requested).concat(includes_for_smart_search)
|
177
171
|
else
|
178
|
-
@includes = associations_has_one
|
172
|
+
@includes = associations_has_one
|
173
|
+
# Avoid eager loading has_one associations pointing to a different database as ORM can't join cross databases
|
174
|
+
.reject { |association| separate_database?(@resource, association) }
|
175
|
+
.map(&:name)
|
179
176
|
end
|
180
177
|
end
|
181
178
|
|
@@ -278,7 +278,13 @@ module ForestLiana
|
|
278
278
|
field[:field] = association.name
|
279
279
|
field[:inverse_of] = inverse_of(association)
|
280
280
|
field[:relationship] = get_relationship_type(association)
|
281
|
-
|
281
|
+
|
282
|
+
ForestLiana::SchemaUtils.disable_filter_and_sort_if_cross_db!(
|
283
|
+
field,
|
284
|
+
association.name.to_s,
|
285
|
+
ForestLiana.name_for(@model)
|
286
|
+
)
|
287
|
+
# NOTICE: Create the fields of hasOne, HasMany, … relationships.
|
282
288
|
else
|
283
289
|
collection.fields << get_schema_for_association(association)
|
284
290
|
end
|
@@ -346,7 +352,7 @@ module ForestLiana
|
|
346
352
|
end
|
347
353
|
|
348
354
|
def get_schema_for_association(association)
|
349
|
-
{
|
355
|
+
opts ={
|
350
356
|
field: association.name.to_s,
|
351
357
|
type: get_type_for_association(association),
|
352
358
|
relationship: get_relationship_type(association),
|
@@ -363,6 +369,14 @@ module ForestLiana
|
|
363
369
|
widget: nil,
|
364
370
|
validations: []
|
365
371
|
}
|
372
|
+
|
373
|
+
ForestLiana::SchemaUtils.disable_filter_and_sort_if_cross_db!(
|
374
|
+
opts,
|
375
|
+
association.name.to_s,
|
376
|
+
ForestLiana.name_for(@model)
|
377
|
+
)
|
378
|
+
|
379
|
+
opts
|
366
380
|
end
|
367
381
|
|
368
382
|
def get_relationship_type(association)
|
@@ -126,5 +126,27 @@ module ForestLiana
|
|
126
126
|
def self.is_active_type? model
|
127
127
|
Object.const_defined?('ActiveType::Object') && model < ActiveType::Object
|
128
128
|
end
|
129
|
+
|
130
|
+
def self.disable_filter_and_sort_if_cross_db!(opts, name, collection_name)
|
131
|
+
return unless opts[:reference]
|
132
|
+
|
133
|
+
assoc_name = opts[:reference].split('.').first&.underscore&.to_sym || name
|
134
|
+
model = find_model_from_collection_name(collection_name)
|
135
|
+
return unless model
|
136
|
+
|
137
|
+
association = model.reflect_on_association(assoc_name)
|
138
|
+
return unless association
|
139
|
+
return if polymorphic?(association)
|
140
|
+
|
141
|
+
model_db = model.connection_db_config.database
|
142
|
+
assoc_db = association.klass.connection_db_config.database
|
143
|
+
|
144
|
+
if model_db != assoc_db
|
145
|
+
opts[:is_filterable] = false
|
146
|
+
opts[:is_sortable] = false
|
147
|
+
end
|
148
|
+
rescue => e
|
149
|
+
FOREST_LOGGER.warn("Could not evaluate cross-db association for #{name}: #{e.message}")
|
150
|
+
end
|
129
151
|
end
|
130
152
|
end
|
data/lib/forest_liana/version.rb
CHANGED
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.14.
|
4
|
+
version: 9.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Munda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|