feat(models): Sequelize associations across the full entity graph#54
Merged
Conversation
Wires up hasMany / belongsTo for every FK in the schema, centralized
in db.config.js so the relationship graph is visible in one file
rather than scattered across 18 model definitions. JS-side only —
the DB-level FK constraints remain authoritative via setup/*.sql +
the migrations; associations here enable Sequelize \`include\`
(eager loading) and the auto-generated getter/setter methods.
Graph shape:
- Company is the tenancy root: hasMany Customer, Worker,
BillingType, InventoryItem, ApiKey, TimeEntry,
PurchaseOrderVendor, InventoryTransaction
- Customer fans out: TimeEntry, Job, Invoice, CustomerPayment
- Job fans out: InvoiceJob, ProductEntry
- Invoice fans out: InvoiceJob (lines)
- InventoryItem fans in: ProductEntry, InventoryTransaction,
PurchaseOrderLine
- PO chain: Vendor → Header → Line
A handful of FK column names are unusual ("polpoh" lowercase,
"invtInitId" with the BACPAC "init" prefix, "penArch" typo we
match rather than rename) — associations use the actual column
names so eager loads work without aliasing surprises.
Verified by a new unit-test suite (tests/unit/associations.test.js)
that walks Model.associations and asserts each expected edge.
Catches typos and column-name drift early.
Tests: 29 files / 223 (was 28 / 199).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CryptoJones
added a commit
that referenced
this pull request
May 18, 2026
Continues the docs-sync pattern from #44 and #53. CHANGELOG [Unreleased] now reflects: Added: - Sequelize associations (#54) - Integration test harness (#55) - Postman collection (#59) - TLS reverse-proxy compose (#60) - docker-compose.override.yml committed (#56) Fixed: - setup/TimeTracker.sql idempotency (#57) — removes the \`docker compose down -v\` workaround Docs: - Integration bring-up flow (#56, #58) - README sections for Testing and Behind TLS Co-authored-by: Aaron K. Clark <akclark@thenetwerk.net> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wires up
hasMany/belongsToacross all 18 models, centralized indb.config.js. JS-side only — the DB-level FK constraints insetup/*.sql+ migrations remain authoritative. Enables eager loading viaincludeand the auto-generatedget<Foo>()/set<Foo>()helpers.Graph:
FK column oddities mirrored verbatim:
polpoh(lowercase),invtInitId(BACPACinitprefix),penArch(typo).Test plan
tests/unit/associations.test.jswalks each model's.associationsand verifies the expected edges — catches typos and column-name driftincludequery against PG (not run here — see Server: make express.json() body-size limit explicit + env-tunable #45 / docker compose for the live integration path)Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/