paper_trail_diff 0.13.1 → 0.15.0
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 +4 -4
- data/CHANGELOG.md +630 -0
- data/QUICKSTART.md +30 -10
- data/README.md +91 -13
- data/docs/architecture.md +62 -18
- data/docs/performance.md +116 -298
- data/docs/reference.md +554 -102
- data/docs/testing.md +93 -14
- data/lib/paper_trail_diff/activity_belongs_to_event_applier.rb +19 -9
- data/lib/paper_trail_diff/activity_boundary.rb +83 -26
- data/lib/paper_trail_diff/activity_child_candidate_loader.rb +2 -1
- data/lib/paper_trail_diff/activity_collection_event_applier.rb +11 -1
- data/lib/paper_trail_diff/activity_collection_record_updater.rb +16 -2
- data/lib/paper_trail_diff/activity_event.rb +41 -10
- data/lib/paper_trail_diff/activity_event_record_resolver.rb +20 -1
- data/lib/paper_trail_diff/activity_event_route_finder.rb +2 -1
- data/lib/paper_trail_diff/activity_event_snapshot_refresher.rb +1 -1
- data/lib/paper_trail_diff/activity_history.rb +34 -9
- data/lib/paper_trail_diff/activity_range.rb +32 -5
- data/lib/paper_trail_diff/activity_relationship.rb +12 -0
- data/lib/paper_trail_diff/activity_root_snapshot_refresher.rb +5 -2
- data/lib/paper_trail_diff/activity_snapshot_sequence.rb +76 -37
- data/lib/paper_trail_diff/activity_target_candidate_loader.rb +131 -0
- data/lib/paper_trail_diff/activity_timeline_builder.rb +281 -120
- data/lib/paper_trail_diff/activity_transaction_grouper.rb +2 -1
- data/lib/paper_trail_diff/activity_tree_filter.rb +114 -0
- data/lib/paper_trail_diff/activity_version_collector.rb +37 -24
- data/lib/paper_trail_diff/activity_view.rb +69 -0
- data/lib/paper_trail_diff/analysis.rb +13 -1
- data/lib/paper_trail_diff/analysis_batch.rb +24 -30
- data/lib/paper_trail_diff/approximate_paths.rb +48 -0
- data/lib/paper_trail_diff/association_activity_edge.rb +236 -0
- data/lib/paper_trail_diff/association_activity_selection.rb +197 -0
- data/lib/paper_trail_diff/association_discovery.rb +14 -11
- data/lib/paper_trail_diff/association_key.rb +56 -0
- data/lib/paper_trail_diff/association_traversal.rb +180 -47
- data/lib/paper_trail_diff/batch_boundary_resolver.rb +3 -4
- data/lib/paper_trail_diff/batch_preload.rb +53 -0
- data/lib/paper_trail_diff/batched_root_analyzer.rb +12 -14
- data/lib/paper_trail_diff/batched_root_versions.rb +53 -47
- data/lib/paper_trail_diff/change_row.rb +133 -0
- data/lib/paper_trail_diff/collection_comparator.rb +5 -32
- data/lib/paper_trail_diff/comparison_batch.rb +37 -10
- data/lib/paper_trail_diff/configuration.rb +35 -12
- data/lib/paper_trail_diff/deleted_analysis_batch.rb +45 -27
- data/lib/paper_trail_diff/deleted_root_filter.rb +79 -0
- data/lib/paper_trail_diff/deprecation.rb +61 -0
- data/lib/paper_trail_diff/diagnostics.rb +105 -102
- data/lib/paper_trail_diff/direct_record_state_loader.rb +10 -1
- data/lib/paper_trail_diff/endpoint.rb +26 -3
- data/lib/paper_trail_diff/errors.rb +5 -2
- data/lib/paper_trail_diff/fallback_paths.rb +38 -0
- data/lib/paper_trail_diff/habtm_transaction_owners.rb +68 -0
- data/lib/paper_trail_diff/historical_association_reifier.rb +34 -6
- data/lib/paper_trail_diff/historical_filter.rb +19 -10
- data/lib/paper_trail_diff/historical_snapshot_store.rb +63 -76
- data/lib/paper_trail_diff/live_endpoint_batch_loader.rb +12 -13
- data/lib/paper_trail_diff/live_graph_collector.rb +1 -1
- data/lib/paper_trail_diff/nested_comparator.rb +19 -18
- data/lib/paper_trail_diff/paper_trail_adapter.rb +136 -125
- data/lib/paper_trail_diff/preloaded_endpoint_batch_loader.rb +14 -2
- data/lib/paper_trail_diff/prepared_activity_index.rb +110 -36
- data/lib/paper_trail_diff/prepared_edge_loader.rb +31 -46
- data/lib/paper_trail_diff/prepared_history.rb +70 -53
- data/lib/paper_trail_diff/prepared_history_loader.rb +34 -43
- data/lib/paper_trail_diff/prepared_record_index.rb +64 -7
- data/lib/paper_trail_diff/prepared_snapshot_builder.rb +1 -1
- data/lib/paper_trail_diff/prepared_state_association_reader.rb +119 -29
- data/lib/paper_trail_diff/recorded_changes.rb +83 -0
- data/lib/paper_trail_diff/recorded_class.rb +53 -0
- data/lib/paper_trail_diff/root_version_selection.rb +4 -2
- data/lib/paper_trail_diff/scope_condition.rb +386 -0
- data/lib/paper_trail_diff/scope_ranking.rb +206 -0
- data/lib/paper_trail_diff/scoped_analysis.rb +11 -0
- data/lib/paper_trail_diff/scoped_analysis_builder.rb +20 -11
- data/lib/paper_trail_diff/scoped_root_selection.rb +105 -49
- data/lib/paper_trail_diff/snapshot.rb +16 -1
- data/lib/paper_trail_diff/snapshot_normalizer.rb +10 -3
- data/lib/paper_trail_diff/support.rb +38 -6
- data/lib/paper_trail_diff/time_range.rb +37 -18
- data/lib/paper_trail_diff/time_version_range.rb +5 -5
- data/lib/paper_trail_diff/timeline_builder.rb +7 -7
- data/lib/paper_trail_diff/timeline_range.rb +9 -1
- data/lib/paper_trail_diff/timeline_snapshot_provider.rb +24 -17
- data/lib/paper_trail_diff/transaction_cut.rb +181 -0
- data/lib/paper_trail_diff/traversal_preparer.rb +134 -29
- data/lib/paper_trail_diff/version.rb +1 -1
- data/lib/paper_trail_diff/version_association_candidate_scope.rb +13 -3
- data/lib/paper_trail_diff/version_boundary.rb +37 -8
- data/lib/paper_trail_diff/version_query.rb +34 -10
- data/lib/paper_trail_diff/version_range.rb +8 -15
- data/lib/paper_trail_diff/version_scope_filter.rb +20 -13
- data/lib/paper_trail_diff/version_sequence_diagnostics.rb +31 -16
- data/lib/paper_trail_diff/version_table.rb +60 -0
- data/lib/paper_trail_diff.rb +126 -55
- data/sig/generated/paper_trail_diff/activity_belongs_to_event_applier.rbs +10 -2
- data/sig/generated/paper_trail_diff/activity_boundary.rbs +54 -19
- data/sig/generated/paper_trail_diff/activity_collection_event_applier.rbs +5 -0
- data/sig/generated/paper_trail_diff/activity_collection_record_updater.rbs +5 -0
- data/sig/generated/paper_trail_diff/activity_event.rbs +25 -4
- data/sig/generated/paper_trail_diff/activity_event_record_resolver.rbs +7 -0
- data/sig/generated/paper_trail_diff/activity_history.rbs +21 -6
- data/sig/generated/paper_trail_diff/activity_range.rbs +14 -3
- data/sig/generated/paper_trail_diff/activity_relationship.rbs +3 -0
- data/sig/generated/paper_trail_diff/activity_root_snapshot_refresher.rbs +2 -0
- data/sig/generated/paper_trail_diff/activity_snapshot_sequence.rbs +48 -9
- data/sig/generated/paper_trail_diff/activity_target_candidate_loader.rbs +79 -0
- data/sig/generated/paper_trail_diff/activity_timeline_builder.rbs +138 -28
- data/sig/generated/paper_trail_diff/activity_tree_filter.rbs +73 -0
- data/sig/generated/paper_trail_diff/activity_version_collector.rbs +12 -4
- data/sig/generated/paper_trail_diff/activity_view.rbs +42 -0
- data/sig/generated/paper_trail_diff/analysis.rbs +8 -1
- data/sig/generated/paper_trail_diff/analysis_batch.rbs +8 -15
- data/sig/generated/paper_trail_diff/approximate_paths.rbs +23 -0
- data/sig/generated/paper_trail_diff/association_activity_edge.rbs +148 -0
- data/sig/generated/paper_trail_diff/association_activity_selection.rbs +112 -0
- data/sig/generated/paper_trail_diff/association_discovery.rbs +8 -5
- data/sig/generated/paper_trail_diff/association_key.rbs +29 -0
- data/sig/generated/paper_trail_diff/association_traversal.rbs +88 -9
- data/sig/generated/paper_trail_diff/batch_preload.rbs +29 -0
- data/sig/generated/paper_trail_diff/batched_root_analyzer.rbs +9 -10
- data/sig/generated/paper_trail_diff/batched_root_versions.rbs +14 -10
- data/sig/generated/paper_trail_diff/change_row.rbs +86 -0
- data/sig/generated/paper_trail_diff/collection_comparator.rbs +2 -16
- data/sig/generated/paper_trail_diff/comparison_batch.rbs +22 -4
- data/sig/generated/paper_trail_diff/configuration.rbs +19 -3
- data/sig/generated/paper_trail_diff/deleted_analysis_batch.rbs +20 -8
- data/sig/generated/paper_trail_diff/deleted_root_filter.rbs +48 -0
- data/sig/generated/paper_trail_diff/deprecation.rbs +35 -0
- data/sig/generated/paper_trail_diff/diagnostics.rbs +44 -32
- data/sig/generated/paper_trail_diff/direct_record_state_loader.rbs +6 -0
- data/sig/generated/paper_trail_diff/endpoint.rbs +11 -2
- data/sig/generated/paper_trail_diff/errors.rbs +5 -2
- data/sig/generated/paper_trail_diff/fallback_paths.rbs +22 -0
- data/sig/generated/paper_trail_diff/habtm_transaction_owners.rbs +40 -0
- data/sig/generated/paper_trail_diff/historical_association_reifier.rbs +13 -0
- data/sig/generated/paper_trail_diff/historical_filter.rbs +12 -2
- data/sig/generated/paper_trail_diff/historical_snapshot_store.rbs +36 -30
- data/sig/generated/paper_trail_diff/live_endpoint_batch_loader.rbs +5 -3
- data/sig/generated/paper_trail_diff/nested_comparator.rbs +10 -7
- data/sig/generated/paper_trail_diff/paper_trail_adapter.rbs +55 -48
- data/sig/generated/paper_trail_diff/preloaded_endpoint_batch_loader.rbs +9 -1
- data/sig/generated/paper_trail_diff/prepared_activity_index.rbs +52 -10
- data/sig/generated/paper_trail_diff/prepared_edge_loader.rbs +4 -12
- data/sig/generated/paper_trail_diff/prepared_history.rbs +40 -24
- data/sig/generated/paper_trail_diff/prepared_history_loader.rbs +15 -13
- data/sig/generated/paper_trail_diff/prepared_record_index.rbs +34 -2
- data/sig/generated/paper_trail_diff/prepared_state_association_reader.rbs +56 -11
- data/sig/generated/paper_trail_diff/recorded_changes.rbs +47 -0
- data/sig/generated/paper_trail_diff/recorded_class.rbs +22 -0
- data/sig/generated/paper_trail_diff/root_version_selection.rbs +2 -0
- data/sig/generated/paper_trail_diff/scope_condition.rbs +219 -0
- data/sig/generated/paper_trail_diff/scope_ranking.rbs +125 -0
- data/sig/generated/paper_trail_diff/scoped_analysis.rbs +6 -0
- data/sig/generated/paper_trail_diff/scoped_analysis_builder.rbs +8 -3
- data/sig/generated/paper_trail_diff/scoped_root_selection.rbs +49 -11
- data/sig/generated/paper_trail_diff/snapshot.rbs +8 -0
- data/sig/generated/paper_trail_diff/snapshot_normalizer.rbs +6 -0
- data/sig/generated/paper_trail_diff/support.rbs +20 -2
- data/sig/generated/paper_trail_diff/time_range.rbs +20 -2
- data/sig/generated/paper_trail_diff/time_version_range.rbs +4 -4
- data/sig/generated/paper_trail_diff/timeline_builder.rbs +2 -2
- data/sig/generated/paper_trail_diff/timeline_range.rbs +2 -0
- data/sig/generated/paper_trail_diff/timeline_snapshot_provider.rbs +17 -7
- data/sig/generated/paper_trail_diff/transaction_cut.rbs +94 -0
- data/sig/generated/paper_trail_diff/traversal_preparer.rbs +66 -8
- data/sig/generated/paper_trail_diff/version_association_candidate_scope.rbs +7 -0
- data/sig/generated/paper_trail_diff/version_boundary.rbs +20 -3
- data/sig/generated/paper_trail_diff/version_query.rbs +18 -2
- data/sig/generated/paper_trail_diff/version_range.rbs +4 -2
- data/sig/generated/paper_trail_diff/version_scope_filter.rbs +7 -4
- data/sig/generated/paper_trail_diff/version_sequence_diagnostics.rbs +16 -9
- data/sig/generated/paper_trail_diff/version_table.rbs +30 -0
- data/sig/generated/paper_trail_diff.rbs +47 -25
- metadata +62 -10
- data/lib/paper_trail_diff/activity_grouping.rb +0 -38
- data/lib/paper_trail_diff/batch_safety.rb +0 -55
- data/lib/paper_trail_diff/time_activity_timeline_builder.rb +0 -224
- data/sig/generated/paper_trail_diff/activity_grouping.rbs +0 -22
- data/sig/generated/paper_trail_diff/batch_safety.rbs +0 -24
- data/sig/generated/paper_trail_diff/time_activity_timeline_builder.rbs +0 -92
|
@@ -10,39 +10,93 @@ module PaperTrailDiff
|
|
|
10
10
|
@range = ActivityRange.new(start_at, end_at)
|
|
11
11
|
@roots = root_versions.group_by { |version| [version.item_type, version.item_id.to_s] }
|
|
12
12
|
@nodes = {} #: Hash[String, Array[untyped]]
|
|
13
|
-
|
|
14
|
-
@
|
|
13
|
+
# Rows are cached by reflection, which a subclass shares with its base.
|
|
14
|
+
@children = {} #: Hash[untyped, untyped]
|
|
15
|
+
@targets = {} #: Hash[untyped, untyped]
|
|
16
|
+
@rows = {} #: Hash[untyped, Hash[String, Array[untyped]]]
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
#: (untyped, Array[untyped]) -> void
|
|
18
20
|
def register(model, ids)
|
|
19
|
-
name = model.base_class.name
|
|
21
|
+
name = model.base_class.name
|
|
20
22
|
@nodes[name] = (@nodes.fetch(name, []) | ids)
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
#: (untyped, Array[untyped]) -> Array[untyped]
|
|
24
26
|
def versions(model, ids)
|
|
25
27
|
ids.flat_map do |id|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
@roots[[model.base_class.name, id.to_s]] || @records.versions_for_id(model, id)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Children are found by key across the whole table, so an association to
|
|
33
|
+
# an STI subclass finds the rows of its siblings too. Only a row that was
|
|
34
|
+
# of the class at some point belongs to it, and of that row only the
|
|
35
|
+
# versions it had the class before or after.
|
|
36
|
+
#: (untyped, Array[untyped]) -> Array[untyped]
|
|
37
|
+
def member_ids(model, ids)
|
|
38
|
+
return ids if model.descends_from_active_record?
|
|
39
|
+
|
|
40
|
+
ids.select { |id| member_class?(model, @records.model_classes(model, id)) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
#: (untyped, Array[untyped], ActivityRange) -> Array[untyped]
|
|
44
|
+
def member_versions(model, ids, range)
|
|
45
|
+
all = versions(model, ids).select { |version| range.include?(version) }
|
|
46
|
+
return all if model.descends_from_active_record?
|
|
47
|
+
|
|
48
|
+
all.select do |version|
|
|
49
|
+
member_class?(model, @records.model_classes(model, version.item_id, version))
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# The versions of a through's join rows that are on its path. Under
|
|
54
|
+
# `source_type:`, a row is on it only while its type column names that
|
|
55
|
+
# class, so only the versions it had that type before or after count. A
|
|
56
|
+
# version saved before the type column existed has no type to read.
|
|
57
|
+
#: (Hash[Symbol, untyped], untyped) -> Array[untyped]
|
|
58
|
+
def join_versions(group, reflection)
|
|
59
|
+
versions = group.fetch(:versions)
|
|
60
|
+
source_type = reflection.options[:source_type]
|
|
61
|
+
return versions unless source_type
|
|
62
|
+
|
|
63
|
+
column = reflection.foreign_type
|
|
64
|
+
versions.select do |version|
|
|
65
|
+
@records.states_around(group.fetch(:model), version.item_id, version).any? do |state|
|
|
66
|
+
state.attributes[column] == source_type.to_s
|
|
67
|
+
end
|
|
28
68
|
end
|
|
29
69
|
end
|
|
30
70
|
|
|
31
71
|
#: (untyped, Array[untyped], untyped, ActivityRange) -> Array[untyped]
|
|
32
72
|
def child_ids(model, ids, reflection, range)
|
|
33
|
-
|
|
34
|
-
historical, live = @children[key] ||= child_rows(model, reflection)
|
|
73
|
+
historical, live = @children[reflection] ||= child_rows(model, reflection)
|
|
35
74
|
empty = [] #: Array[untyped]
|
|
36
75
|
selected = historical_ids(reflection.klass, ids, historical, range)
|
|
37
76
|
selected |= ids.flat_map { |id| live.fetch(id.to_s, empty) } if range.current_end?
|
|
38
77
|
selected.uniq
|
|
39
78
|
end
|
|
40
79
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
80
|
+
# The `belongs_to` targets each owner pointed at in the range: at its start
|
|
81
|
+
# and after each change inside it, plus the live row at a current end.
|
|
82
|
+
#: (untyped, Array[untyped], untyped, ActivityRange) -> Array[ActivityTargetCandidateLoader::Row]
|
|
83
|
+
def target_rows(model, ids, reflection, range)
|
|
84
|
+
historical, live = @targets[reflection] ||= target_candidates(model, reflection)
|
|
85
|
+
rows = eligible_rows(model, rows_for(historical, ids), range)
|
|
86
|
+
range.current_end? ? rows + rows_for(live, ids) : rows
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
#: (untyped, untyped) -> bool
|
|
90
|
+
def loaded?(model, id)
|
|
91
|
+
@records.loaded?(model, id)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# PT-AT records HABTM membership once per transaction, under the
|
|
95
|
+
# association's name, so the rows are keyed by transaction id.
|
|
96
|
+
#: (untyped, Array[untyped], untyped) -> Array[untyped]
|
|
97
|
+
def habtm_rows(model, selected_versions, reflection)
|
|
98
|
+
rows = @rows[reflection] ||= load_habtm_rows(model, reflection)
|
|
99
|
+
transaction_ids(selected_versions).flat_map { |id| rows.fetch(id.to_s, []) }
|
|
46
100
|
end
|
|
47
101
|
|
|
48
102
|
private
|
|
@@ -51,22 +105,29 @@ module PaperTrailDiff
|
|
|
51
105
|
# @rbs @range: ActivityRange
|
|
52
106
|
# @rbs @roots: Hash[Array[String], Array[untyped]]
|
|
53
107
|
# @rbs @nodes: Hash[String, Array[untyped]]
|
|
54
|
-
# @rbs @children: Hash[
|
|
55
|
-
# @rbs @
|
|
108
|
+
# @rbs @children: Hash[untyped, untyped]
|
|
109
|
+
# @rbs @targets: Hash[untyped, untyped]
|
|
110
|
+
# @rbs @rows: Hash[untyped, Hash[String, Array[untyped]]]
|
|
111
|
+
|
|
112
|
+
#: (untyped, Array[untyped]) -> bool
|
|
113
|
+
def member_class?(model, classes)
|
|
114
|
+
classes.any? { |model_class| model_class <= model }
|
|
115
|
+
end
|
|
56
116
|
|
|
57
117
|
#: (untyped, Array[untyped], untyped, ActivityRange) -> Array[untyped]
|
|
58
118
|
def historical_ids(model, ids, historical, range)
|
|
59
119
|
empty = [] #: Array[untyped]
|
|
60
120
|
ids.flat_map do |id|
|
|
61
121
|
historical.fetch(id.to_s, empty).filter_map do |row|
|
|
62
|
-
|
|
122
|
+
_owner, child_id, timestamp, event = row
|
|
123
|
+
child_id if eligible_version?(model, child_id, timestamp, event, range)
|
|
63
124
|
end
|
|
64
125
|
end
|
|
65
126
|
end
|
|
66
127
|
|
|
67
128
|
#: (untyped) -> Array[untyped]
|
|
68
129
|
def node_ids(model)
|
|
69
|
-
name = model.base_class.name
|
|
130
|
+
name = model.base_class.name
|
|
70
131
|
@nodes.fetch(name) do
|
|
71
132
|
raise ConfigurationError,
|
|
72
133
|
"prepared activity graph is missing #{name}; " \
|
|
@@ -84,12 +145,31 @@ module PaperTrailDiff
|
|
|
84
145
|
.transform_values { |rows| rows.map(&:last) }]
|
|
85
146
|
end
|
|
86
147
|
|
|
148
|
+
#: (Hash[String, Array[ActivityTargetCandidateLoader::Row]], Array[untyped]) -> Array[ActivityTargetCandidateLoader::Row]
|
|
149
|
+
def rows_for(grouped, ids)
|
|
150
|
+
ids.flat_map { |id| grouped[id.to_s] || [] }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
#: (untyped, Array[ActivityTargetCandidateLoader::Row], ActivityRange) -> Array[ActivityTargetCandidateLoader::Row]
|
|
154
|
+
def eligible_rows(model, rows, range)
|
|
155
|
+
rows.select do |row|
|
|
156
|
+
eligible_version?(model, row.owner_id, row.created_at, row.event, range) &&
|
|
157
|
+
range.recorded_before_end?(row.created_at, row.version_id)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
#: (untyped, untyped) -> untyped
|
|
162
|
+
def target_candidates(model, reflection)
|
|
163
|
+
loader = ActivityTargetCandidateLoader.new(model, node_ids(model), reflection, @range)
|
|
164
|
+
[loader.historical_rows.group_by { |row| row.owner_id.to_s },
|
|
165
|
+
loader.current_rows.group_by { |row| row.owner_id.to_s }]
|
|
166
|
+
end
|
|
167
|
+
|
|
87
168
|
# Mirrors VersionAssociationCandidateScope's before-window rule. The loaded
|
|
88
169
|
# series includes changes to other owners too, so an old membership cannot
|
|
89
170
|
# survive a later pre-window reassignment just because that owner is absent.
|
|
90
|
-
#: (untyped,
|
|
91
|
-
def
|
|
92
|
-
_owner, id, timestamp, event = row
|
|
171
|
+
#: (untyped, untyped, untyped, String?, ActivityRange) -> bool
|
|
172
|
+
def eligible_version?(model, id, timestamp, event, range)
|
|
93
173
|
return timestamp <= range.end_time if timestamp >= range.start_time
|
|
94
174
|
return false if event == 'destroy'
|
|
95
175
|
|
|
@@ -98,24 +178,18 @@ module PaperTrailDiff
|
|
|
98
178
|
!later || later.created_at >= range.start_time
|
|
99
179
|
end
|
|
100
180
|
|
|
101
|
-
#: (untyped, untyped
|
|
102
|
-
def
|
|
103
|
-
all_versions = versions(model, node_ids(model))
|
|
104
|
-
foreign_key = transactions ? reflection.name.to_s : reflection.foreign_key.to_s
|
|
181
|
+
#: (untyped, untyped) -> Hash[String, Array[untyped]]
|
|
182
|
+
def load_habtm_rows(model, reflection)
|
|
105
183
|
model.paper_trail.version_association_class.where(
|
|
106
|
-
version_id:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
end.uniq
|
|
116
|
-
else
|
|
117
|
-
versions.map(&:id)
|
|
118
|
-
end
|
|
184
|
+
version_id: transaction_ids(versions(model, node_ids(model))),
|
|
185
|
+
foreign_key_name: reflection.name
|
|
186
|
+
).group_by { |row| row.version_id.to_s }
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# A version without a transaction id names no rows, so it can stay in.
|
|
190
|
+
#: (Array[untyped]) -> Array[untyped]
|
|
191
|
+
def transaction_ids(versions)
|
|
192
|
+
versions.map { |version| VersionBoundary.transaction_id(version) }.uniq
|
|
119
193
|
end
|
|
120
194
|
end
|
|
121
195
|
end
|
|
@@ -4,25 +4,21 @@
|
|
|
4
4
|
module PaperTrailDiff
|
|
5
5
|
# Loads every historical identity that can participate in one association edge.
|
|
6
6
|
class PreparedEdgeLoader
|
|
7
|
-
EDGE_LOADERS = {
|
|
8
|
-
belongs_to: :belongs_to_edge,
|
|
9
|
-
has_one: :child_edge,
|
|
10
|
-
has_many: :child_edge,
|
|
11
|
-
has_and_belongs_to_many: :habtm_edge
|
|
12
|
-
}.freeze
|
|
13
|
-
private_constant :EDGE_LOADERS
|
|
14
|
-
|
|
15
7
|
#: (PreparedRecordIndex, Array[untyped], ?start_at: untyped) -> void
|
|
16
8
|
def initialize(records, root_versions, start_at: root_versions.first&.created_at)
|
|
17
9
|
@records = records
|
|
18
|
-
@transaction_ids = root_versions.filter_map(&:transaction_id)
|
|
10
|
+
@transaction_ids = root_versions.filter_map(&:transaction_id)
|
|
19
11
|
@start_at = start_at
|
|
20
12
|
end
|
|
21
13
|
|
|
14
|
+
# HABTM alone also returns each root transaction's members.
|
|
22
15
|
#: (untyped, Array[untyped], untyped) -> [Hash[String, Hash[Symbol, untyped]], Hash[String, Array[untyped]]?]
|
|
23
16
|
def call(owner_class, owner_ids, reflection)
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
case reflection.macro
|
|
18
|
+
when :belongs_to then [belongs_to_groups(owner_class, owner_ids, reflection), nil]
|
|
19
|
+
when :has_and_belongs_to_many then habtm_groups(owner_class, reflection)
|
|
20
|
+
else [child_groups(owner_class, owner_ids, reflection), nil]
|
|
21
|
+
end
|
|
26
22
|
end
|
|
27
23
|
|
|
28
24
|
private
|
|
@@ -31,21 +27,6 @@ module PaperTrailDiff
|
|
|
31
27
|
# @rbs @transaction_ids: Array[untyped]
|
|
32
28
|
# @rbs @start_at: untyped
|
|
33
29
|
|
|
34
|
-
#: (untyped, Array[untyped], untyped) -> [Hash[String, Hash[Symbol, untyped]], nil]
|
|
35
|
-
def belongs_to_edge(owner_class, owner_ids, reflection)
|
|
36
|
-
[belongs_to_groups(owner_class, owner_ids, reflection), nil]
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
#: (untyped, Array[untyped], untyped) -> [Hash[String, Hash[Symbol, untyped]], nil]
|
|
40
|
-
def child_edge(owner_class, owner_ids, reflection)
|
|
41
|
-
[child_groups(owner_class, owner_ids, reflection), nil]
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
#: (untyped, Array[untyped], untyped) -> [Hash[String, Hash[Symbol, untyped]], Hash[String, Array[untyped]]]
|
|
45
|
-
def habtm_edge(owner_class, _owner_ids, reflection)
|
|
46
|
-
habtm_groups(owner_class, reflection)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
30
|
#: (untyped, Array[untyped], untyped) -> Hash[String, Hash[Symbol, untyped]]
|
|
50
31
|
def belongs_to_groups(owner_class, owner_ids, reflection)
|
|
51
32
|
key = scalar_foreign_key(reflection)
|
|
@@ -56,9 +37,12 @@ module PaperTrailDiff
|
|
|
56
37
|
end
|
|
57
38
|
|
|
58
39
|
grouped = {} #: Hash[String, Hash[Symbol, untyped]]
|
|
40
|
+
# Grouping only decides what to preload, so a type that names no class is
|
|
41
|
+
# left to raise where that state is read.
|
|
59
42
|
@records.records_for(owner_class, owner_ids).each do |owner|
|
|
60
43
|
id = owner.public_send(key)
|
|
61
|
-
|
|
44
|
+
type = owner.public_send(reflection.foreign_type).to_s
|
|
45
|
+
model_class = AssociationTraversal.named_class(type)
|
|
62
46
|
add_identity(grouped, model_class, id) if model_class && id
|
|
63
47
|
end
|
|
64
48
|
grouped
|
|
@@ -75,28 +59,31 @@ module PaperTrailDiff
|
|
|
75
59
|
group_for(reflection.klass, owners.values.flatten, owners: owners)
|
|
76
60
|
end
|
|
77
61
|
|
|
62
|
+
# A transaction more than one owner recorded members in is left out, so
|
|
63
|
+
# its read falls back to HistoricalAssociationReifier, which raises.
|
|
78
64
|
#: (untyped, untyped) -> [Hash[String, Hash[Symbol, untyped]], Hash[String, Array[untyped]]]
|
|
79
65
|
def habtm_groups(owner_class, reflection)
|
|
80
66
|
rows = habtm_rows(owner_class, reflection)
|
|
67
|
+
shared = HabtmTransactionOwners.new(owner_class, reflection).shared(rows.map(&:version_id))
|
|
81
68
|
memberships = @transaction_ids.to_h do |transaction_id|
|
|
82
69
|
[transaction_id.to_s, membership_ids(rows, transaction_id)]
|
|
83
70
|
end
|
|
84
|
-
[group_for(reflection.klass, rows.
|
|
71
|
+
[group_for(reflection.klass, rows.map(&:foreign_key_id)), memberships.except(*shared)]
|
|
85
72
|
end
|
|
86
73
|
|
|
87
74
|
#: (untyped, untyped) -> Array[untyped]
|
|
88
75
|
def habtm_rows(owner_class, reflection)
|
|
89
76
|
owner_class.paper_trail.version_association_class.where(
|
|
90
77
|
version_id: @transaction_ids,
|
|
91
|
-
foreign_key_name: reflection.name
|
|
92
|
-
)
|
|
78
|
+
foreign_key_name: reflection.name
|
|
79
|
+
)
|
|
93
80
|
end
|
|
94
81
|
|
|
95
82
|
#: (Array[untyped], untyped) -> Array[untyped]
|
|
96
83
|
def membership_ids(rows, transaction_id)
|
|
97
84
|
rows.filter_map do |row|
|
|
98
85
|
row.foreign_key_id if row.version_id.to_s == transaction_id.to_s
|
|
99
|
-
end
|
|
86
|
+
end
|
|
100
87
|
end
|
|
101
88
|
|
|
102
89
|
#: (untyped, Array[untyped], untyped, String) -> Hash[String, Array[untyped]]
|
|
@@ -109,7 +96,7 @@ module PaperTrailDiff
|
|
|
109
96
|
version_class = owner_class.paper_trail.version_class
|
|
110
97
|
association_class = owner_class.paper_trail.version_association_class
|
|
111
98
|
relation = historical_child_relation(owner_class, owner_ids, reflection, foreign_key)
|
|
112
|
-
pairs = child_candidate_scope(version_class).call(relation).
|
|
99
|
+
pairs = child_candidate_scope(version_class).call(relation).pluck(
|
|
113
100
|
association_class.arel_table[:foreign_key_id],
|
|
114
101
|
version_class.arel_table[:item_id]
|
|
115
102
|
)
|
|
@@ -124,7 +111,8 @@ module PaperTrailDiff
|
|
|
124
111
|
#: (untyped, Array[untyped], untyped, String) -> untyped
|
|
125
112
|
def historical_child_relation(owner_class, owner_ids, reflection, foreign_key)
|
|
126
113
|
version_class = owner_class.paper_trail.version_class
|
|
127
|
-
owner_class.paper_trail.version_association_class
|
|
114
|
+
associations = owner_class.paper_trail.version_association_class
|
|
115
|
+
VersionTable.joined(associations, version_class).where(
|
|
128
116
|
foreign_key_name: foreign_key,
|
|
129
117
|
foreign_key_id: owner_ids,
|
|
130
118
|
foreign_type: parent_types(owner_class)
|
|
@@ -141,10 +129,10 @@ module PaperTrailDiff
|
|
|
141
129
|
|
|
142
130
|
#: (untyped, Array[untyped], untyped, String) -> Hash[String, Array[untyped]]
|
|
143
131
|
def live_child_ids(owner_class, owner_ids, reflection, foreign_key)
|
|
132
|
+
# Every row of the table, as history reads them: an STI subclass's
|
|
133
|
+
# siblings are left out where children are resolved.
|
|
144
134
|
relation = reflection.klass.base_class.unscoped.where(foreign_key => owner_ids)
|
|
145
|
-
if reflection.
|
|
146
|
-
relation = relation.where(reflection.type => parent_types(owner_class))
|
|
147
|
-
end
|
|
135
|
+
relation = relation.where(reflection.type => parent_types(owner_class)) if reflection.type
|
|
148
136
|
group_ids_by_owner(relation.pluck(foreign_key, reflection.klass.primary_key))
|
|
149
137
|
end
|
|
150
138
|
|
|
@@ -161,18 +149,15 @@ module PaperTrailDiff
|
|
|
161
149
|
|
|
162
150
|
group = { model: model_class, ids: unique } #: Hash[Symbol, untyped]
|
|
163
151
|
group[:owners] = owners if owners
|
|
164
|
-
{ model_class.name
|
|
152
|
+
{ model_class.name => group }
|
|
165
153
|
end
|
|
166
154
|
|
|
167
|
-
#
|
|
155
|
+
# A set rather than a scan, so that a wide edge stays linear in its width.
|
|
168
156
|
#: (Array[Array[untyped]]) -> Hash[String, Array[untyped]]
|
|
169
157
|
def group_ids_by_owner(pairs)
|
|
170
|
-
grouped = {} #: Hash[String,
|
|
171
|
-
pairs.each
|
|
172
|
-
|
|
173
|
-
ids[child_id] = true
|
|
174
|
-
end
|
|
175
|
-
grouped.transform_values(&:keys)
|
|
158
|
+
grouped = {} #: Hash[String, Set[untyped]]
|
|
159
|
+
pairs.each { |owner_id, child_id| (grouped[owner_id.to_s] ||= Set.new) << child_id }
|
|
160
|
+
grouped.transform_values(&:to_a)
|
|
176
161
|
end
|
|
177
162
|
|
|
178
163
|
#: (Hash[String, Array[untyped]], Hash[String, Array[untyped]]) -> Hash[String, Array[untyped]]
|
|
@@ -183,12 +168,12 @@ module PaperTrailDiff
|
|
|
183
168
|
#: (untyped) -> String?
|
|
184
169
|
def scalar_foreign_key(reflection)
|
|
185
170
|
key = reflection.foreign_key
|
|
186
|
-
key
|
|
171
|
+
key unless key.is_a?(Array)
|
|
187
172
|
end
|
|
188
173
|
|
|
189
174
|
#: (untyped) -> Array[String?]
|
|
190
175
|
def parent_types(owner_class)
|
|
191
|
-
[nil, '', owner_class.name
|
|
176
|
+
[nil, '', owner_class.name, owner_class.base_class.name]
|
|
192
177
|
end
|
|
193
178
|
end
|
|
194
179
|
end
|
|
@@ -17,14 +17,16 @@ module PaperTrailDiff
|
|
|
17
17
|
#: (PreparedRecordIndex, ?activity_index: PreparedActivityIndex?) -> void
|
|
18
18
|
def initialize(records, activity_index: nil)
|
|
19
19
|
@records = records
|
|
20
|
-
@
|
|
20
|
+
@conditions = ScopeCondition::Cache.new
|
|
21
|
+
@state_reader = PreparedStateAssociationReader.new(records, method(:edge), @conditions)
|
|
21
22
|
@activity_index = activity_index
|
|
22
23
|
@edges = {} #: Hash[Array[String], Hash[String, Hash[Symbol, untyped]]]
|
|
23
24
|
@unsupported = {} #: Hash[Array[String], bool]
|
|
24
25
|
@habtm = {} #: Hash[Array[String], Hash[String, Array[untyped]]]
|
|
25
26
|
end
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
# Returns every group the edge now holds.
|
|
29
|
+
#: (untyped, untyped, Hash[String, Hash[Symbol, untyped]]) -> Hash[String, Hash[Symbol, untyped]]
|
|
28
30
|
def merge_edge(owner_class, reflection, groups)
|
|
29
31
|
key = edge_key(owner_class, reflection)
|
|
30
32
|
empty = {} #: Hash[String, Hash[Symbol, untyped]]
|
|
@@ -62,14 +64,16 @@ module PaperTrailDiff
|
|
|
62
64
|
@state_reader.call(owner, reflection, boundary)
|
|
63
65
|
end
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
# Unranked, as a part of a has_many through is read, it returns every row
|
|
68
|
+
# the part's conditions admit, a record reached twice appearing twice.
|
|
69
|
+
#: (untyped, untyped, untyped, habtm_boundary: untyped, ?ranked: bool) -> [bool, Array[untyped]]
|
|
70
|
+
def resolve(record, reflection, boundary, habtm_boundary:, ranked: true)
|
|
71
|
+
return [false, []] unless supported?(record.class, reflection, ranked)
|
|
68
72
|
|
|
69
73
|
records = if reflection.options[:through]
|
|
70
|
-
through_records(record, reflection, boundary, habtm_boundary)
|
|
74
|
+
through_records(record, reflection, boundary, habtm_boundary, ranked)
|
|
71
75
|
else
|
|
72
|
-
direct_records(record, reflection, boundary, habtm_boundary)
|
|
76
|
+
direct_records(record, reflection, boundary, habtm_boundary, ranked)
|
|
73
77
|
end
|
|
74
78
|
records ? [true, records] : [false, []]
|
|
75
79
|
end
|
|
@@ -81,31 +85,34 @@ module PaperTrailDiff
|
|
|
81
85
|
# @rbs @edges: Hash[Array[String], Hash[String, Hash[Symbol, untyped]]]
|
|
82
86
|
# @rbs @unsupported: Hash[Array[String], bool]
|
|
83
87
|
# @rbs @habtm: Hash[Array[String], Hash[String, Array[untyped]]]
|
|
88
|
+
# @rbs @conditions: ScopeCondition::Cache
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
# A polymorphic target's class is known only once a record names it, so
|
|
91
|
+
# belongs_to_records reads its scope for each record instead.
|
|
92
|
+
#: (untyped, untyped, bool) -> bool
|
|
93
|
+
def supported?(owner_class, reflection, ranked)
|
|
87
94
|
!@unsupported[edge_key(owner_class, reflection)] &&
|
|
88
|
-
reflection.
|
|
95
|
+
(reflection.polymorphic? || !@conditions.call(reflection, ranked: ranked).nil?)
|
|
89
96
|
end
|
|
90
97
|
|
|
91
|
-
#: (untyped, untyped, untyped, untyped) -> Array[untyped]?
|
|
92
|
-
def direct_records(record, reflection, boundary, habtm_boundary)
|
|
98
|
+
#: (untyped, untyped, untyped, untyped, bool) -> Array[untyped]?
|
|
99
|
+
def direct_records(record, reflection, boundary, habtm_boundary, ranked)
|
|
93
100
|
resolver = DIRECT_RESOLVERS.fetch(reflection.macro)
|
|
94
|
-
send(resolver, record, reflection, boundary, habtm_boundary)
|
|
101
|
+
send(resolver, record, reflection, boundary, habtm_boundary, ranked)
|
|
95
102
|
end
|
|
96
103
|
|
|
97
|
-
#: (untyped, untyped, untyped, untyped) -> Array[untyped]?
|
|
98
|
-
def resolve_belongs_to(record, reflection, boundary, _habtm_boundary)
|
|
99
|
-
belongs_to_records(record, reflection, boundary)
|
|
104
|
+
#: (untyped, untyped, untyped, untyped, bool) -> Array[untyped]?
|
|
105
|
+
def resolve_belongs_to(record, reflection, boundary, _habtm_boundary, ranked)
|
|
106
|
+
belongs_to_records(record, reflection, boundary, ranked)
|
|
100
107
|
end
|
|
101
108
|
|
|
102
|
-
#: (untyped, untyped, untyped, untyped) -> Array[untyped]
|
|
103
|
-
def resolve_children(record, reflection, boundary, _habtm_boundary)
|
|
104
|
-
child_records(record, reflection, boundary)
|
|
109
|
+
#: (untyped, untyped, untyped, untyped, bool) -> Array[untyped]
|
|
110
|
+
def resolve_children(record, reflection, boundary, _habtm_boundary, ranked)
|
|
111
|
+
child_records(record, reflection, boundary, ranked)
|
|
105
112
|
end
|
|
106
113
|
|
|
107
|
-
#: (untyped, untyped, untyped) -> Array[untyped]?
|
|
108
|
-
def belongs_to_records(record, reflection, boundary)
|
|
114
|
+
#: (untyped, untyped, untyped, bool) -> Array[untyped]?
|
|
115
|
+
def belongs_to_records(record, reflection, boundary, ranked)
|
|
109
116
|
foreign_key = scalar_foreign_key(reflection)
|
|
110
117
|
return unless foreign_key
|
|
111
118
|
|
|
@@ -113,20 +120,23 @@ module PaperTrailDiff
|
|
|
113
120
|
return [] if id.nil?
|
|
114
121
|
|
|
115
122
|
model_class = AssociationTraversal.belongs_to_target(reflection, record)
|
|
116
|
-
return unless model_class && @
|
|
123
|
+
return unless model_class && @conditions.call(reflection, model_class, ranked: ranked) &&
|
|
124
|
+
@records.loaded?(model_class, id)
|
|
117
125
|
|
|
118
|
-
Array(@records.record_before(model_class, id, boundary)).compact
|
|
126
|
+
target = Array(@records.record_before(model_class, id, boundary)).compact
|
|
127
|
+
@conditions.select(reflection, target, model_class, ranked: ranked)
|
|
119
128
|
end
|
|
120
129
|
|
|
121
|
-
#: (untyped, untyped, untyped) -> Array[untyped]
|
|
122
|
-
def child_records(record, reflection, boundary)
|
|
123
|
-
edge(record.class, reflection).values.flat_map do |group|
|
|
130
|
+
#: (untyped, untyped, untyped, bool) -> Array[untyped]
|
|
131
|
+
def child_records(record, reflection, boundary, ranked)
|
|
132
|
+
children = edge(record.class, reflection).values.flat_map do |group|
|
|
124
133
|
model_class = group.fetch(:model)
|
|
125
134
|
child_ids_for(group, record).filter_map do |id|
|
|
126
135
|
child = @records.record_before(model_class, id, boundary)
|
|
127
136
|
child if child && member_of?(child, reflection, record)
|
|
128
137
|
end
|
|
129
138
|
end
|
|
139
|
+
@conditions.select(reflection, children, ranked: ranked)
|
|
130
140
|
end
|
|
131
141
|
|
|
132
142
|
#: (Hash[Symbol, untyped], untyped) -> Array[untyped]
|
|
@@ -136,8 +146,13 @@ module PaperTrailDiff
|
|
|
136
146
|
owners ? owners.fetch(owner.id.to_s, empty) : group.fetch(:ids)
|
|
137
147
|
end
|
|
138
148
|
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
# PT-AT records a checkpoint's membership as it is when the checkpoint is
|
|
150
|
+
# saved, so a tag attached earlier in the checkpoint's own transaction is a
|
|
151
|
+
# member there, unlike other associations, which a version reads as they
|
|
152
|
+
# were before its transaction. A member created in that transaction has no
|
|
153
|
+
# earlier state, so it is read as it was created.
|
|
154
|
+
#: (untyped, untyped, untyped, untyped, bool) -> Array[untyped]?
|
|
155
|
+
def habtm_records(record, reflection, boundary, habtm_boundary, ranked)
|
|
141
156
|
transaction_id = transaction_id_for(habtm_boundary)
|
|
142
157
|
return unless transaction_id
|
|
143
158
|
|
|
@@ -145,37 +160,38 @@ module PaperTrailDiff
|
|
|
145
160
|
ids = @habtm.fetch(edge_key(record.class, reflection), empty)[transaction_id.to_s]
|
|
146
161
|
return unless ids
|
|
147
162
|
|
|
148
|
-
ids.filter_map do |id|
|
|
149
|
-
@records.record_before(reflection.klass, id, boundary)
|
|
163
|
+
members = ids.filter_map do |id|
|
|
164
|
+
@records.record_before(reflection.klass, id, boundary) ||
|
|
165
|
+
@records.record_created_in(reflection.klass, id, habtm_boundary)
|
|
150
166
|
end
|
|
167
|
+
@conditions.select(reflection, members, ranked: ranked)
|
|
151
168
|
end
|
|
152
169
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
habtm_boundary: habtm_boundary
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return unless resolved.all?(&:first)
|
|
170
|
+
# A has_many through reads its parts unranked, as its query does. Its own
|
|
171
|
+
# scope applies to each row, and a ranked read then keeps a record reached
|
|
172
|
+
# twice as one member.
|
|
173
|
+
#: (untyped, untyped, untyped, untyped, bool) -> Array[untyped]?
|
|
174
|
+
def through_records(record, reflection, boundary, habtm_boundary, ranked)
|
|
175
|
+
read = lambda do |owner, part|
|
|
176
|
+
resolve(owner, part, boundary, habtm_boundary: habtm_boundary,
|
|
177
|
+
ranked: ranked && !reflection.collection?)
|
|
178
|
+
end
|
|
179
|
+
rows = through_rows(record, reflection, read)
|
|
180
|
+
return unless rows
|
|
165
181
|
|
|
166
|
-
|
|
182
|
+
rows = @conditions.select(reflection, rows, ranked: ranked)
|
|
183
|
+
ranked ? unique_records(rows) : rows
|
|
167
184
|
end
|
|
168
185
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
end
|
|
186
|
+
# The source records of each join record, once for each join.
|
|
187
|
+
#: (untyped, untyped, ^(untyped, untyped) -> [bool, Array[untyped]]) -> Array[untyped]?
|
|
188
|
+
def through_rows(record, reflection, read)
|
|
189
|
+
handled, joins = read.call(record, reflection.through_reflection)
|
|
190
|
+
return unless handled
|
|
191
|
+
|
|
192
|
+
joins = joins.select { |join| AssociationTraversal.source_type_join?(reflection, join) }
|
|
193
|
+
resolved = joins.map { |join| read.call(join, reflection.source_reflection) }
|
|
194
|
+
resolved.flat_map(&:last) if resolved.all?(&:first)
|
|
179
195
|
end
|
|
180
196
|
|
|
181
197
|
#: (untyped, untyped, untyped) -> bool
|
|
@@ -183,6 +199,7 @@ module PaperTrailDiff
|
|
|
183
199
|
foreign_key = scalar_foreign_key(reflection)
|
|
184
200
|
return false unless foreign_key
|
|
185
201
|
return false unless child.public_send(foreign_key).to_s == owner.id.to_s
|
|
202
|
+
return false unless AssociationTraversal.sti_member?(reflection.klass, child.attributes)
|
|
186
203
|
return true unless reflection.options[:as]
|
|
187
204
|
|
|
188
205
|
owner_types(reflection, owner).include?(child.public_send(reflection.type).to_s)
|