iknow_view_models 3.11.0 → 3.12.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38a806928f1c5c2d76aadb5970b72abeabb5f579bde7164ba0b90de9ed6781ea
|
4
|
+
data.tar.gz: fa7c33062381a8414be49bc82b87bc938f5bdad278f10f55cb5b64aa0115eb4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c1b31614c56224a94331c75ff2e44080acda5d92aced69ab0e73dbc2fece60e710ae2e066f69fdf42f0726cd1c80ab7ec762ed24cac36e1343f54f4584bff60
|
7
|
+
data.tar.gz: fd9b38a254a62fbc67cbe2a0c668e8e3a49ca2474df4a39bf9f1344e60076aaefb8ea01d7e5196a1408a1bfaa2ab3f1f2ec624ea050bca16098b89e78ed3d919
|
@@ -522,6 +522,10 @@ class ViewModel::ActiveRecord
|
|
522
522
|
|
523
523
|
delegate :new?, :child_update?, :auto_child_update?, to: :metadata
|
524
524
|
|
525
|
+
def reference_only?
|
526
|
+
attributes.empty? && associations.empty? && referenced_associations.empty?
|
527
|
+
end
|
528
|
+
|
525
529
|
def self.parse_hashes(root_subtree_hashes, referenced_subtree_hashes = {})
|
526
530
|
valid_reference_keys = referenced_subtree_hashes.keys.to_set
|
527
531
|
|
@@ -44,6 +44,10 @@ class ViewModel::ActiveRecord
|
|
44
44
|
@built
|
45
45
|
end
|
46
46
|
|
47
|
+
def reference_only?
|
48
|
+
update_data.reference_only? && reparent_to.nil? && reposition_to.nil?
|
49
|
+
end
|
50
|
+
|
47
51
|
# Evaluate a built update tree, applying and saving changes to the models.
|
48
52
|
def run!(deserialize_context:)
|
49
53
|
raise ViewModel::DeserializationError::Internal.new('Internal error: UpdateOperation run before build') unless built?
|
@@ -123,9 +127,14 @@ class ViewModel::ActiveRecord
|
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
126
|
-
#
|
127
|
-
|
128
|
-
|
130
|
+
# If a request makes no assertions about the model, we don't demand
|
131
|
+
# that the current state of the model is valid. This permits making
|
132
|
+
# edits to other models that refer to this model when this model is
|
133
|
+
# invalid.
|
134
|
+
unless reference_only? && !viewmodel.new_model?
|
135
|
+
deserialize_context.run_callback(ViewModel::Callbacks::Hook::BeforeValidate, viewmodel)
|
136
|
+
viewmodel.validate!
|
137
|
+
end
|
129
138
|
|
130
139
|
# Save if the model has been altered. Covers not only models with
|
131
140
|
# view changes but also lock version assertions.
|
@@ -291,6 +291,8 @@ class ViewModel::ActiveRecord < ViewModel::Record
|
|
291
291
|
hook_control.record_changes(changes)
|
292
292
|
model.destroy!
|
293
293
|
end
|
294
|
+
rescue ::ActiveRecord::StatementInvalid, ::ActiveRecord::InvalidForeignKey, ::ActiveRecord::RecordNotSaved => e
|
295
|
+
raise ViewModel::DeserializationError::DatabaseConstraint.from_exception(e, self.blame_reference)
|
294
296
|
end
|
295
297
|
end
|
296
298
|
|
data/lib/view_model/migration.rb
CHANGED
@@ -5,8 +5,18 @@ class ViewModel::Migration
|
|
5
5
|
require 'view_model/migration/one_way_error'
|
6
6
|
require 'view_model/migration/unspecified_version_error'
|
7
7
|
|
8
|
+
REFERENCE_ONLY_KEYS = [
|
9
|
+
ViewModel::TYPE_ATTRIBUTE,
|
10
|
+
ViewModel::ID_ATTRIBUTE,
|
11
|
+
ViewModel::VERSION_ATTRIBUTE,
|
12
|
+
].freeze
|
13
|
+
|
8
14
|
def up(view, _references)
|
9
|
-
|
15
|
+
# Only a reference-only view may be (trivially) migrated up without an
|
16
|
+
# explicit migration.
|
17
|
+
if (view.keys - REFERENCE_ONLY_KEYS).present?
|
18
|
+
raise ViewModel::Migration::OneWayError.new(view[ViewModel::TYPE_ATTRIBUTE], :up)
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
def down(view, _references)
|
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.
|
4
|
+
version: 3.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iKnow Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|