Skip to content

fix: add MODX table prefix to relation field table names#136

Merged
biz87 merged 2 commits intobetafrom
fix/grid-relation-table-prefix
Mar 10, 2026
Merged

fix: add MODX table prefix to relation field table names#136
biz87 merged 2 commits intobetafrom
fix/grid-relation-table-prefix

Conversation

@biz87
Copy link
Copy Markdown
Member

@biz87 biz87 commented Mar 10, 2026

Summary

  • Relation fields in grid config utility (e.g. orders_count with COUNT() on ms3_orders) returned zeros because the MODX table prefix was not applied to direct table names
  • GridConfigService::validateRelationConfig() now adds the table prefix when saving relation config with a direct table name
  • CustomersController::fetchRelationData() adds a fallback prefix check for configs already saved without prefix

Test plan

  • Create a relation field in grid config with a direct table name (e.g. ms3_orders)
  • Verify the aggregated values display correctly (not zeros)
  • Verify that entering a table name with prefix already included does not double-prefix
  • Test on installations with different table prefixes (e.g. modx_, empty)

biz87 added 2 commits March 10, 2026 23:02
When users configure relation fields via grid config utility with direct
table names (e.g. ms3_orders), the MODX table prefix was not applied.
This caused SQL queries in fetchRelationData() to reference non-existent
tables, silently returning zeros for all aggregate values.

Fix applied in two places:
- GridConfigService::validateRelationConfig() — prefix added on save
- CustomersController::fetchRelationData() — fallback for existing configs
Review fix: getTableName() returns backtick-quoted names like
`modx_ms3_orders`. The fallback prefix check in fetchRelationData()
incorrectly added prefix to already-resolved names because strpos
missed the leading backtick. Now skips prefixing for backtick-quoted
names. Also: strpos → str_starts_with (PHP 8.2+), marked fallback
as temporary with removal guidance.
@biz87 biz87 merged commit 97590f4 into beta Mar 10, 2026
@Ibochkarev Ibochkarev deleted the fix/grid-relation-table-prefix branch March 16, 2026 07:09
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