Skip to content

[#16052] Fix Query balias lcfirst for namespaced models#16909

Merged
niden merged 1 commit intophalcon:5.0.xfrom
niden-code:T16052-query-balias-lcase
Apr 23, 2026
Merged

[#16052] Fix Query balias lcfirst for namespaced models#16909
niden merged 1 commit intophalcon:5.0.xfrom
niden-code:T16052-query-balias-lcase

Conversation

@niden
Copy link
Copy Markdown
Member

@niden niden commented Apr 23, 2026

Description

When using find() with a columns option that triggers a complex resultset (e.g. '*, "ready" AS stat'), the model object is stored inside the Row under a key computed from its class name. The key was always built with lcfirst(modelName), which works fine for non-namespaced models (Robotsrobots) but produces a confusing, hard-to-predict result for namespaced models (App\Models\Usersapp\Models\Users instead of App\Models\Users).

Users had to work around this by calling lcfirst(\App\Models\Users::class) themselves:

// before — unintuitive workaround required
$row->offsetGet(lcfirst(\App\Models\Users::class)); // app\Models\Users

// after — class name used directly
$row->offsetGet(\App\Models\Users::class); // App\Models\Users

Changes

  • phalcon/Mvc/Model/Query.zepgetSelectColumn(): when computing balias for PHQL_T_STARALL (SELECT *) and PHQL_T_DOMAINALL (SELECT alias.*), apply lcfirst() only when the model name contains no namespace separator (\); otherwise use the model name as-is.
  • tests/database/Mvc/Model/QueryTest.php — removed the lcfirst() workaround from the transform() helper that was relying on the old behaviour.

Backward compatibility

Non-namespaced model names (e.g. Robots, Invoices) continue to produce the same lcfirst() key as before (robots, invoices). Only namespaced models are affected.

Related

Fixes #16052

…espaced models

When building a complex resultset from SELECT * or SELECT alias.*, the
balias key used to access the model object inside a Row was always
computed with lcfirst(modelName). For namespaced models this produced
an unintuitive and hard-to-predict key (e.g. app\Models\Users instead
of App\Models\Users). Non-namespaced models (e.g. Robots -> robots)
are unaffected.

Fixes phalcon#16052
@niden niden requested a review from Jeckerson April 23, 2026 19:19
@niden niden self-assigned this Apr 23, 2026
@niden niden added bug A bug report 5.0 The issues we want to solve in the 5.0 release labels Apr 23, 2026
@niden niden added this to Phalcon v5 Apr 23, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in Phalcon v5 Apr 23, 2026
@niden niden moved this from Backlog to In Progress in Phalcon v5 Apr 23, 2026
@niden niden added the status: medium Medium label Apr 23, 2026
@niden niden marked this pull request as ready for review April 23, 2026 19:30
@niden niden merged commit 791be80 into phalcon:5.0.x Apr 23, 2026
63 of 82 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Implemented in Phalcon v5 Apr 23, 2026
@niden niden deleted the T16052-query-balias-lcase branch April 23, 2026 22:37
@niden niden mentioned this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Projects

Status: Implemented

Development

Successfully merging this pull request may close these issues.

1 participant