-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quote strategy not applied to foreign key columns #6402
Comments
AFAIKS it's a duplicate of #5874 :/ |
@theofidry it's similar, but not a duplicate. @lemartin is the join column mapped with backticks? |
Yes, the column is mapped with back-ticks. /**
* @OneToOne(targetEntity="User", inversedBy="address")
* @JoinColumn(name="`user-id`", referencedColumnName="`user-id`")
*/
public $user; |
Yup, that's 100% a bug then, and not a duplicate :-\ |
After some debugging I think I found a fix, but also another bug. See below the diff for fixing the original issue. I'm not sure if the map is really necessary, or if there is an easier way to find the What I am really unsure about is, what is supposed to go into There the quoted column name is passed to The tests are no help, they succeed regardless if the quoted or unquoted column name is passed. diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php
index 9c4ac2a..5e5ae62 100644
--- a/lib/Doctrine/ORM/Query/SqlWalker.php
+++ b/lib/Doctrine/ORM/Query/SqlWalker.php
@@ -756,12 +756,18 @@ class SqlWalker implements TreeWalker
$targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
+ $columnNameToJoinColumn = [];
+ foreach($assoc['joinColumns'] as &$joinColumn) {
+ $columnNameToJoinColumn[$joinColumn['name']] = $joinColumn;
+ }
+
foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) {
$columnAlias = $this->getSQLColumnAlias($srcColumn);
+ $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($columnNameToJoinColumn[$srcColumn], $class, $this->platform);
$type = null;
$isIdentifier = (isset($assoc['id']) && $assoc['id'] === true);
- $sqlSelectExpressions[] = $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias;
+ $sqlSelectExpressions[] = $sqlTableAlias . '.' . $quotedSourceColumn . ' AS ' . $columnAlias;
if (isset($targetClass->fieldNames[$targetColumn])) {
$type = $targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type']; |
Created a pull request for both issues. (My first ever, sorry if I got anything wrong). The PR targets the master, how are the chances, given a PR for 2.5 would be supplied, that this fix could find its way into a 2.5.x? |
Apply quoting strategy to foreign key columns of one-to-one relation so that correct select statements are generated. And use unquoted column names in result mapping instead of quoted ones, as consumers (namely IdentifierFlattener) expect unquoted column names.
Closed by #6404 |
Handled in #6416 |
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.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 asAs 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 (48e8c02):
The text was updated successfully, but these errors were encountered: