Quote strategy not applied to foreign key columns #5503

Open
opened 2026-01-22 15:09:19 +01:00 by admin · 0 comments
Owner

Originally created by @lemartin on GitHub (Apr 17, 2017).

Originally assigned to: @lcobucci on GitHub.

The quote strategy is not applied to foreign key columns used in one-to-one associations. When fetching the Address entity the column user-id is not quoted.

SELECT 
  q0_."address-id" AS addressid_0,
  q0_."address-zip" AS addresszip_1,
  q0_.user-id AS userid_2
FROM "quote-address" q0_

The tests do not cover this scenario, as they force partially loaded entities. Applying the patch below should yield a failing test case. The columns come from a collection called targetToSourceKeyColumns where, if I understood correctly, all columns are stored that are used as

As far as I can tell, the problem is in SqlWalker::walkSelectClause, where the foreign key columns are added to the list of select expressions.

Patch for creating a test case, based on branch 2.5 (48e8c02cb8):

diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
index a3a34f8..21b6961 100644
--- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
+++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -1972,0 +1973,6 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
+
+        $this->assertSqlGeneration(
+            'SELECT a FROM Doctrine\Tests\Models\Quote\Address a',
+            'SELECT q0_."address-id" AS addressid_0, q0_."address-zip" AS addresszip_1, q0_."user-id" AS userid_2 FROM "quote-address" q0_',
+            [Query::HINT_FORCE_PARTIAL_LOAD => false]
+        );
Originally created by @lemartin on GitHub (Apr 17, 2017). Originally assigned to: @lcobucci on GitHub. The quote strategy is not applied to foreign key columns used in one-to-one associations. When fetching the [Address entity](https://github.com/doctrine/doctrine2/blob/2.5/tests/Doctrine/Tests/Models/Quote/Address.php) the column `user-id` is not quoted. ```sql SELECT q0_."address-id" AS addressid_0, q0_."address-zip" AS addresszip_1, q0_.user-id AS userid_2 FROM "quote-address" q0_ ``` The tests do not cover this scenario, as they force partially loaded entities. Applying the patch below should yield a failing test case. The columns come from a collection called `targetToSourceKeyColumns` where, if I understood correctly, all columns are stored that are used as As far as I can tell, the problem is in `SqlWalker::walkSelectClause`, where the foreign key columns are added to the list of select expressions. Patch for creating a test case, based on branch 2.5 (48e8c02cb8c20d10240248b0232e31bf785b0209): ```diff diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index a3a34f8..21b6961 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1972,0 +1973,6 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase + + $this->assertSqlGeneration( + 'SELECT a FROM Doctrine\Tests\Models\Quote\Address a', + 'SELECT q0_."address-id" AS addressid_0, q0_."address-zip" AS addresszip_1, q0_."user-id" AS userid_2 FROM "quote-address" q0_', + [Query::HINT_FORCE_PARTIAL_LOAD => false] + ); ```
admin added the Bug label 2026-01-22 15:09:19 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5503