Document Connection - Parent-Child Model
Overview
CONA uses a hierarchical parent-child relationship model for connecting documents, moving away from bidirectional “to/from” connections to create clearer document hierarchies. This approach provides better organization around primary documents (like sales orders) while avoiding complex interconnected networks.Key Concepts
Parent-Child Hierarchy
- One child can have many parents - A document can be related to multiple parent documents
- One parent can have many children - A parent document can have multiple child documents
- No “cousins” or “partners” - Documents are only connected through direct parent-child relationships
- Clear hierarchy - Usually revolves around a primary document like a sales order
Typical Document Hierarchy
Implementation
Database Schema
Thedocument_relations table uses:
parent_document_id- References the parent documentchild_document_id- References the child document- Unique constraint on
(parent_document_id, child_document_id)to prevent duplicates
Core Functions
connectDocuments()
Creates parent-child relationships between documents.
batchConnectDocuments()
Efficiently creates multiple parent-child relationships in a single transaction.
Usage in Integrations
Shopify Integration
- Sales Order → Parent document
- Sales Invoice → Child of sales order
- Credit Note → Child of both sales order and sales invoice
Reconciliation
Parent Priority Order:- Inherited Parents → If any document already has a parent, all documents inherit that parent
- Sales Invoice → Becomes parent when available and no existing parents
- Fallback → First document becomes parent if no invoice or existing parents
- Payment reconciles with Invoice (Invoice has Sales Order parent) → Payment inherits Sales Order as parent
- Payment reconciles with standalone Invoice → Invoice becomes parent of Payment
- Payment reconciles with Credit Note → First document becomes parent
Benefits
- Clear Hierarchy - Easy to understand document relationships
- Scalable - Avoids complex interconnected networks
- Flexible - Supports multiple parents per child when needed
- Organized - Centers around primary business documents
- Efficient - Simpler queries for finding related documents