iknow_view_models 3.2.12 → 3.2.13

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: 284af292a0f1a70b761afd2e3ef084ad9f8f5853f00c8af8ac2d3b1227eb9cb5
4
- data.tar.gz: 61fdea22a0b13db50e7b237e472900eef376e95d04fed5f21a8c1ef7422aaa56
3
+ metadata.gz: 3991314cdb010347b417869ff3e2e22b0e7adb4ab590e25739cb6b12bf49a219
4
+ data.tar.gz: 0cd5994d07bdd9b9d311732be56b01a51d7b4f1eb71f7fa1d0217bf71911b97f
5
5
  SHA512:
6
- metadata.gz: 64ffd808756c298236f4e00b11cdf7f1410019bc506f306c6cfbaa97b953212a5c58e7b56263deac0aac5e80398fa2d551922d6b90d7a3c60732a50b66467384
7
- data.tar.gz: ccd3301209a94c8e9cd9a44166b153ae3edafab81cfe49498849e6c22dc413956d33e3cdba0ab001456122f47400df47dfbe327d9a9005f1947c512da3d9e523
6
+ metadata.gz: a5cd70dd6f79db33a97dbdfb05eefec460c7e332784839ad461cf5a359307ce8abedb39c046d42d04a3b7355280d1ad54948cb6cc61fdc35effa0f684ea4c821
7
+ data.tar.gz: 6a673b6387892588434f981b57f8131e9c7a97991cc16d3901e72f043b9429efd0fef7a8e1f44cb0ea1ee364256d63d48f198a10e270b487d3da61311780eec7
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.2.12'
4
+ VERSION = '3.2.13'
5
5
  end
@@ -182,9 +182,14 @@ class ViewModel::ActiveRecord < ViewModel::Record
182
182
  end
183
183
 
184
184
  # Constructs a preload specification of the required models for
185
- # serializing/deserializing this view.
186
- def eager_includes(serialize_context: new_serialize_context, include_referenced: true)
185
+ # serializing/deserializing this view. Cycles in the schema will be broken
186
+ # after two layers of eager loading.
187
+ def eager_includes(serialize_context: new_serialize_context, include_referenced: true, vm_path: [])
187
188
  association_specs = {}
189
+
190
+ return nil if vm_path.count(self) > 2
191
+
192
+ child_path = vm_path + [self]
188
193
  _members.each do |assoc_name, association_data|
189
194
  next unless association_data.is_a?(AssociationData)
190
195
  next if association_data.external?
@@ -201,7 +206,7 @@ class ViewModel::ActiveRecord < ViewModel::Record
201
206
  case
202
207
  when association_data.through?
203
208
  viewmodel = association_data.direct_viewmodel
204
- children = viewmodel.eager_includes(serialize_context: child_context, include_referenced: include_referenced)
209
+ children = viewmodel.eager_includes(serialize_context: child_context, include_referenced: include_referenced, vm_path: child_path)
205
210
 
206
211
  when !include_referenced && association_data.referenced?
207
212
  children = nil # Load up to the root viewmodel, but no further
@@ -210,13 +215,13 @@ class ViewModel::ActiveRecord < ViewModel::Record
210
215
  children_by_klass = {}
211
216
  association_data.viewmodel_classes.each do |vm_class|
212
217
  klass = vm_class.model_class.name
213
- children_by_klass[klass] = vm_class.eager_includes(serialize_context: child_context, include_referenced: include_referenced)
218
+ children_by_klass[klass] = vm_class.eager_includes(serialize_context: child_context, include_referenced: include_referenced, vm_path: child_path)
214
219
  end
215
220
  children = DeepPreloader::PolymorphicSpec.new(children_by_klass)
216
221
 
217
222
  else
218
223
  viewmodel = association_data.viewmodel_class
219
- children = viewmodel.eager_includes(serialize_context: child_context, include_referenced: include_referenced)
224
+ children = viewmodel.eager_includes(serialize_context: child_context, include_referenced: include_referenced, vm_path: child_path)
220
225
  end
221
226
 
222
227
  association_specs[association_data.direct_reflection.name.to_s] = children
@@ -416,6 +416,11 @@ class ViewModel::ActiveRecordTest < ActiveSupport::TestCase
416
416
  @list = List.new(child: List.new(child: nil))
417
417
  end
418
418
 
419
+ def test_list_eager_includes
420
+ expected_includes = 3.times.inject(nil) { |x| DeepPreloader::Spec.new({ 'child' => x }) }
421
+ assert_equal(expected_includes, ListView.eager_includes)
422
+ end
423
+
419
424
  def test_deserialize_context
420
425
  view = {
421
426
  '_type' => 'List',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.12
4
+ version: 3.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-15 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord