Skip to content

fix(cubejs): scaffolded cubes with joins get a primary-key dimension#70

Merged
acmeguy merged 1 commit into
mainfrom
fix/scaffold-primary-keys
Jul 13, 2026
Merged

fix(cubejs): scaffolded cubes with joins get a primary-key dimension#70
acmeguy merged 1 commit into
mainfrom
fix/scaffold-primary-keys

Conversation

@acmeguy

@acmeguy acmeguy commented Jul 13, 2026

Copy link
Copy Markdown

ScaffoldingTemplate emits belongsTo joins for FK-pattern columns but only auto-marks a primary key for columns literally named id. Schemas keyed <table>_id (e.g. Pagila) then scaffold cubes with joins and no primary_key — the whole branch fails to compile (primary key for X is required when join is defined) and the datasource's meta serves zero cubes.

Fix: post-process YAML scaffolds — when a cube has joins and no primary-key dimension, promote the id-pattern column to a hidden primary-key dimension.

Surfaced by cxs2 spec 081 (US7b: connect Pagila → generate models → Tychi refine → dashboard). Verified locally: 3-table Pagila scaffold now compiles and serves Film/Customer/Rental.

🤖 Generated with Claude Code

ScaffoldingTemplate emits belongsTo joins for FK-pattern columns but only
auto-marks a primary key for columns literally named 'id'. Schemas keyed
with '<table>_id' (e.g. Pagila) then scaffold cubes that have joins and no
primary_key — and the whole branch fails to compile ('primary key for X is
required when join is defined'), so generate-models produces a datasource
whose meta serves ZERO cubes.

Post-process YAML scaffolds: when a cube has joins and no primary-key
dimension, promote the id-pattern column (id / <table>_id / trailing _id
not used by a join) to a hidden primary-key dimension.

Surfaced by cxs2 spec 081 (US7b: connect Pagila -> generate models ->
dashboard); verified against the local stack.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@acmeguy acmeguy merged commit 1262e38 into main Jul 13, 2026
acmeguy added a commit that referenced this pull request Jul 13, 2026
Follow-up to #70: cube requires a primary key on BOTH sides of a join —
'primary key for X is required when join is defined' also fires for the
referenced cube (Rental belongsTo Customer ⇒ Customer needs a pk). Add the
hidden id-pattern primary-key dimension to every scaffolded cube that has
one, not only cubes that own joins. Verified: 3-table Pagila scaffold now
compiles and serves Rental/Film/Customer.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant