Skip to content

Accept an aliased-table array in Sql::select() - #272

Merged
simon-mundy merged 10 commits into
php-db:0.6.xfrom
simon-mundy:fix/271-select-aliased-table
Dec 1, 2026
Merged

simon-mundy merged 10 commits into
php-db:0.6.xfrom
simon-mundy:fix/271-select-aliased-table

Conversation

@simon-mundy

Copy link
Copy Markdown
Member

Fixes #271

Problem

Sql::select() types its table as string|TableIdentifier|null, so $sql->select(['f' => 'foo']) is a TypeError. new Select(['f' => 'foo']) and ->from(['f' => 'foo']) accept the [alias => table] form, and laminas-db's Sql::select() rendered it.

Fix

  • Sql::select() takes array|string|TableIdentifier|null, matching the Select constructor, with a @param describing the array shape.

What stays the same

  • update() and delete(). Their statements keep an aliased table only for TableGateway and render the bare table, so widening them would let Sql build SQL the database rejects. laminas-db never rendered an aliased update or delete either (it produced UPDATE `Array` with a warning).
  • The "table fixed at construction" guard: forForeignTable() already accepts the array form.

Tests

  • SqlTest: select(['f' => 'foo']) returns a Select with that table, renders SELECT "f".* FROM "foo" AS "f", and still throws when the Sql object has a fixed table. SqlTest also gains its #[Group('unit')].
  • The three new tests fail without the fix. Unit suite: 2877 tests pass. mago lint is clean and mago analyze (1.62.0) reports only the findings already on 0.6.x.
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sql::select() typed its table as string|TableIdentifier|null, so
$sql->select(['f' => 'foo']) raised a TypeError, although the Select
constructor and from() accept the [alias => table] form and laminas-db
rendered it. Widen the parameter to match, so the call renders
SELECT "f".* FROM "foo" AS "f" again.

update() and delete() are left as they are: their statements render the
bare table and drop the alias, and laminas-db never rendered an aliased
update or delete either.

Fixes php-db#271

Signed-off-by: Simon Mundy <simon.mundy@peptolab.com>
@simon-mundy
simon-mundy force-pushed the fix/271-select-aliased-table branch from 7ec39d8 to d22fb49 Compare December 1, 2026 02:39
@simon-mundy simon-mundy added this to the 0.6.0 milestone Dec 1, 2026
@github-project-automation github-project-automation Bot moved this to Todo in @phpdb Dec 1, 2026
@simon-mundy simon-mundy added bug Something isn't working documentation Improvements or additions to documentation qa Improvements in quality assurance of the project labels Dec 1, 2026
@simon-mundy simon-mundy self-assigned this Dec 1, 2026
@simon-mundy
simon-mundy requested a review from tyrsson December 1, 2026 02:52
simon-mundy and others added 8 commits December 1, 2026 14:01
Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com>
Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com>
Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com>
Signed-off-by: Simon Mundy <46739456+simon-mundy@users.noreply.github.com>
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in @phpdb Dec 1, 2026
@simon-mundy
simon-mundy merged commit b1eb10f into php-db:0.6.x Dec 1, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in @phpdb Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation qa Improvements in quality assurance of the project

2 participants