Skip to main content

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

The document_relations table uses:
  • parent_document_id - References the parent document
  • child_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:
  1. Inherited Parents → If any document already has a parent, all documents inherit that parent
  2. Sales Invoice → Becomes parent when available and no existing parents
  3. Fallback → First document becomes parent if no invoice or existing parents
Examples:
  • 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

  1. Clear Hierarchy - Easy to understand document relationships
  2. Scalable - Avoids complex interconnected networks
  3. Flexible - Supports multiple parents per child when needed
  4. Organized - Centers around primary business documents
  5. Efficient - Simpler queries for finding related documents

Find Children of a Parent

Find Parents of a Child

Find Siblings (same parent)