Module: Bulkrax::CsvRow::CircularReference
- Defined in:
- app/validators/bulkrax/csv_row/circular_reference.rb
Overview
Detects circular parent-child relationships in the CSV. A circular reference occurs when following the parent chain from any record eventually leads back to itself (e.g. A→B→C→A).
The validator builds a directed graph (child → parents) from all records on first invocation and caches the set of all record ids involved in any cycle. Subsequent per-row calls simply check membership in that set.
Requires context key:
:relationship_graph – Hash { source_identifier => [parent_ids] } built by
run_row_validators before iterating rows.
Class Method Summary collapse
Class Method Details
.call(record, row_index, context) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/validators/bulkrax/csv_row/circular_reference.rb', line 18 def self.call(record, row_index, context) cycle_ids = context[:circular_reference_ids] ||= detect_cycle_ids(context[:relationship_graph] || {}) return unless cycle_ids.include?(record[:source_identifier]) context[:errors] << { row: row_index, source_identifier: record[:source_identifier], severity: 'error', category: 'circular_reference', column: 'parents', value: record[:source_identifier], message: I18n.t('bulkrax.importer.guided_import.validation.circular_reference_validator.errors.message', value: record[:source_identifier]), suggestion: I18n.t('bulkrax.importer.guided_import.validation.circular_reference_validator.errors.suggestion') } end |