Commit 57eccec
authored
Add nested_attributes flag for object: mappings (#1193)
* Add nested_attributes flag for object: mappings
Field mappings can now declare nested_attributes: true alongside an
object: target. When the flag is set, Bulkrax routes the imported data
through parsed_metadata['<name>_attributes'] as a numbered-key hash with
'_destroy: false' markers — the shape Reform's nested-attributes
machinery and similar populators consume directly.
Without the flag, callers had to add hardcoded translators (e.g.
ValkyrieObjectFactory#convert_based_near_to_attributes) to rename
parsed_metadata['<name>'] into the form their downstream form expected.
The flag generalizes that rename so each new nested-attribute consumer
declares its needs in the mapping rather than in factory code.
Also makes object_metadata on export tolerant of plain hashes (in
addition to the legacy stringified-hash literal). Resources backed by
JSONB or similar non-string persistence return Ruby hashes directly;
calling eval on them would fail. The legacy stringified path still
works for ActiveFedora-backed resources.
* Add round-trip spec for nested_attributes flag
Confirms that a single field-mapping declaration drives both directions:
imported numbered columns become _attributes-shaped data the form
populator consumes, and the persisted plain-hash array exports back to
the same numbered columns.
* Permit nested *_attributes keys in object factory
When a field-mapping declares nested_attributes: true, the parsed
metadata arrives at the object factory with a *_attributes virtual
key (e.g. redirects_attributes). The slice in #transform_attributes
was dropping these keys because permitted_attributes only listed
bare schema properties, so downstream form populators received
nothing and the data silently disappeared.
permitted_attributes now allows a *_attributes key through whenever
the corresponding bare property is itself permitted. Generic — any
nested-attributes property added in the future works without further
changes here.
* Expand object: properties in CSV template columns
When a property declared on a model (e.g. redirects) is the target of
one or more `object:` field-mappings, the CSV template now emits each
of those mappings' `from:` columns (e.g. redirect_path, redirect_canonical,
redirect_sequence) instead of the bare property name. Adopters get a
template that matches the column shape Bulkrax actually consumes for
nested-attribute imports.
* Tighten suffix validation to require known base
Headers ending in `_<digits>` previously bypassed validation regardless
of the base name, which masked typos like `creater_1` at validation
time even though the real importer would fail to map the column.
A suffixed header now passes validation only when its base name is
itself recognised — either present in valid_headers directly or
resolvable via the mapping manager to a known property — mirroring the
recognition rule already used for unsuffixed headers in
find_unrecognized_validation_headers.
Adds spec coverage for both the bare and numbered forms of an
`object:` mapping with `nested_attributes: true`, and a regression
spec for the typo-with-suffix case the new rule now catches.
* Keep object: columns in CSV template downloads
The CSV builder prunes columns whose data rows are all blank, so per-
child columns from `object:` mappings (e.g. redirect_path) were getting
dropped from the downloaded template even when they appeared in the
column-builder output. The row builder didn't recognise them as
belonging to a known property — `mapped_to_key('redirect_path')`
returned `path`, which isn't in the model's properties list.
ValueDeterminer now consults the mapping's `object:` value: if the
key isn't a property but its object name is, the cell is filled
("Required"/"Optional") based on the parent property. The columns
survive the empty-column pruning and reach the user.
* Memoize known_property_keys in check_headers
The known-property set was being rebuilt on every suffixed header
header_base_recognized? checked. Computing the set once in
check_headers and passing it down avoids the repeated allocations
during validation of CSVs with many numbered columns.
Behavior is unchanged.1 parent 2df78bd commit 57eccec
15 files changed
Lines changed: 513 additions & 37 deletions
File tree
- app
- factories/bulkrax
- models
- bulkrax
- concerns/bulkrax
- parsers/concerns/bulkrax/csv_parser
- services/bulkrax/csv_template
- spec
- models/bulkrax
- parsers/bulkrax/csv_parser
- services/bulkrax/csv_template
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
471 | | - | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
472 | 489 | | |
473 | 490 | | |
474 | 491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
509 | 510 | | |
510 | 511 | | |
511 | 512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
341 | 340 | | |
342 | 341 | | |
343 | 342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
63 | 87 | | |
64 | 88 | | |
65 | 89 | | |
| |||
69 | 93 | | |
70 | 94 | | |
71 | 95 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
81 | 111 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
88 | 123 | | |
89 | 124 | | |
90 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
88 | 96 | | |
89 | 97 | | |
90 | 98 | | |
| |||
96 | 104 | | |
97 | 105 | | |
98 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
99 | 121 | | |
100 | 122 | | |
101 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
29 | 51 | | |
30 | 52 | | |
31 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | | - | |
| 18 | + | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
| |||
0 commit comments