-
-
Notifications
You must be signed in to change notification settings - Fork 885
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
fix api-platform/#360 QueryChecker with class join #1301
Conversation
soyuka
commented
Aug 2, 2017
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | api-platform/api-platform#360 |
License | MIT |
Doc PR | na |
|
||
$parentMetadata = QueryJoinParser::getClassMetadataFromJoinAlias($parentAlias, $queryBuilder, $managerRegistry); | ||
if (class_exists($relationship)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is the best thing to do though
list($parentAlias, $association) = explode('.', $relationship); | ||
|
||
$parentMetadata = QueryJoinParser::getClassMetadataFromJoinAlias($parentAlias, $queryBuilder, $managerRegistry); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to reverse condition, will be cleaner
4d68d98
to
b40c191
Compare
|
||
$parentMetadata = QueryJoinParser::getClassMetadataFromJoinAlias($parentAlias, $queryBuilder, $managerRegistry); | ||
if (!class_exists($relationship)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO a regex is better than the class_exists
method which use the autoloading:
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+$/', $relationship)) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yes, or we can do:
- a try/catch thing
- test if relation is in the association mapping
strpos
for adot
in the realtionship
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strpos for a dot in the realtionship
Sounds good and better for performance since dots are not allowed in FQCN!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm not sure strpos is sufficient because getJoinRelationship
returns the association alone:
$join = new Join('INNER_JOIN', 'relatedDummy', 'a_1', null, 'a_1.name = r.name');
$this->assertEquals('relatedDummy', QueryJoinParser::getJoinRelationship($join));
b40c191
to
210ffc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add a test for "dotted" joins!
|
210ffc6
to
b0b0089
Compare
I've reviewed the code, there are a lot of assumptions in the QueryChecker/QueryJoinParser but I think it'll be fine. AFAIR we can't have an alias without |
Guilty as charged. 😆 |
if (empty($orderByAliases)) { | ||
return false; | ||
} | ||
|
||
if (!empty($orderByAliases)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is useless now isn't it?
@@ -135,20 +135,44 @@ public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, Manage | |||
} | |||
} | |||
|
|||
if (empty($orderByAliases)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!$orderByAliases)
?
->getManagerForClass($rootEntity) | ||
->getClassMetadata($rootEntity); | ||
|
||
if (!($rootMetadata instanceof ClassMetadata)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!$rootMetadata instanceof ClassMetadata)
(useless parenthesis).
e285cc6
to
79f3615
Compare
79f3615
to
9f9da0c
Compare
Thanks @soyuka! |
fix api-platform/api-platform#360 QueryChecker with class join