Great question about audit trail integrity - this is where understanding Qualio’s compliance module architecture really matters. The solution requires breaking the circular FK dependency while maintaining full traceability for regulatory requirements.
Entity-Relationship Diagram Validation:
The ERD validator in Qualio 2022.2 performs deep transitive dependency analysis specifically to prevent circular references that could cause cascade delete issues or infinite loops in relationship traversal. Your error indicates a four-entity cycle that must be broken at one point.
Recommended Schema Design:
SubmissionDocument (PK: doc_id)
├─> ComplianceAudit (FK: audit_id, document_id)
├─> ApprovalWorkflow (FK: workflow_id, audit_id)
└─> workflow_metadata (JSON: {"source_document_id": "..."})
Foreign Key Constraints:
Implement hard FKs for SubmissionDocument → ComplianceAudit and ComplianceAudit → ApprovalWorkflow. For the reverse reference from ApprovalWorkflow to SubmissionDocument, use a metadata field instead of a FK. This passes ERD validation while maintaining the relationship.
Compliance Document Schema:
In your SubmissionDocument entity, add a related_workflows computed field that queries ApprovalWorkflow records. Qualio’s ORM will handle this efficiently:
SELECT w.* FROM ApprovalWorkflow w
JOIN ComplianceAudit a ON w.audit_id = a.audit_id
WHERE a.document_id = [current_doc_id]
Integration with Audit and Approval Flows:
Qualio’s audit logging operates at the entity change level, not the FK traversal level. Whether you navigate via FK or query doesn’t affect audit trail completeness. Every entity modification is logged with full context including the user action, timestamp, and changed fields. The audit trail will show:
- Document creation/modification events
- Audit record linkage (via the hard FK)
- Workflow state changes (with document_id in metadata)
- Approval decisions tied to specific audits
The key insight is that audit trail integrity comes from entity-level change tracking, not relationship navigation method. Your compliance reports and regulatory submissions will have complete traceability because all entity changes are logged regardless of how the relationships are queried.
Implementation Steps:
- Remove the FK from ApprovalWorkflow back to SubmissionDocument
- Add
source_document_id as a regular varchar field (not FK) in ApprovalWorkflow
- Create a database view or computed field for reverse navigation
- Update your application layer to populate source_document_id when creating workflows
- Re-run ERD validation - it should pass
This design pattern is standard in Qualio compliance implementations where bidirectional navigation is required but circular FKs would violate validation rules. You maintain full functionality and audit integrity while satisfying the ERD validator.