-
-
Notifications
You must be signed in to change notification settings - Fork 101
Improve qb validation #553
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
Changes from all commits
2416752
a56b830
5fa4e2c
e0ad9f0
8fc1db1
9bab892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,6 @@ protected function getPhpcrProperty($originalAlias, $odmField) | |
$this->validateAlias($originalAlias); | ||
$meta = $this->aliasMetadata[$originalAlias];; | ||
|
||
|
||
if ($meta->hasField($odmField)) { | ||
$fieldMeta = $meta->getField($odmField); | ||
} elseif ($meta->hasAssociation($odmField)) { | ||
|
@@ -637,9 +636,30 @@ protected function walkConstraintNot(ConstraintNot $node) | |
|
||
protected function walkOperandDynamicField(OperandDynamicField $node) | ||
{ | ||
$alias = $node->getAlias(); | ||
$field = $node->getField(); | ||
|
||
$classMeta = $this->aliasMetadata[$alias]; | ||
|
||
if ($field === $classMeta->nodename) { | ||
throw new InvalidArgumentException(sprintf( | ||
'Cannot use nodename property "%s->%s" in a field operand; use "localname()" instead.', | ||
$classMeta->name, | ||
$field | ||
)); | ||
} | ||
|
||
if ($classMeta->hasAssociation($field)) { | ||
throw new InvalidArgumentException(sprintf( | ||
'Cannot use association property "%s->%s" in a field operand.', | ||
$classMeta->name, | ||
$field | ||
)); | ||
} | ||
|
||
list($alias, $phpcrProperty) = $this->getPhpcrProperty( | ||
$node->getAlias(), | ||
$node->getField() | ||
$alias, | ||
$field | ||
); | ||
|
||
$op = $this->qomf->propertyValue( | ||
|
@@ -751,6 +771,29 @@ protected function walkOrderBy(OrderBy $node) | |
QBConstants::NT_OPERAND_DYNAMIC | ||
); | ||
|
||
if ($dynOp instanceof OperandDynamicField) { | ||
$alias = $dynOp->getAlias(); | ||
$field = $dynOp->getField(); | ||
|
||
$classMeta = $this->aliasMetadata[$alias]; | ||
|
||
if ($field === $classMeta->nodename) { | ||
throw new InvalidArgumentException(sprintf( | ||
'It is not possible to order by a nodename property "%s->%s"', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this repeat the logic in walkDynamicFieldOperand? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah .. but the key bit is giving a different error message to make it easier to figure out what one did wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that we repeat this code - and it also should be repeated for walking constriants, and by extension we should do the same for all other places where there are invalid things. In short, we should handle this error once. I would rather the exception were more expressive at the source:
For example. But this would require us to boost the query builders self-awareness a little so that it is capable of producing such a trail. But I think that should be another issue. What do you think? Otherwise I would be happy to remove the validation from the orderBy and only have it in the other method. The user should be able to relate the field name to their query and solve the problem. |
||
$classMeta->name, | ||
$field | ||
)); | ||
} | ||
|
||
if ($classMeta->hasAssociation($field)) { | ||
throw new InvalidArgumentException(sprintf( | ||
'It is not possible to order by an association field "%s->%s"', | ||
$classMeta->name, | ||
$field | ||
)); | ||
} | ||
} | ||
|
||
$phpcrDynOp = $this->dispatch($dynOp); | ||
|
||
if ($ordering->getOrder() == QOMConstants::JCR_ORDER_ASCENDING) { | ||
|
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.
maybe the method name is not ideal, but is this method just for handling order by?
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.
No iirc, its for handling all dynamic operands, e.g.
->field('a.foo')
(i.e.PropertyValueInterface
in PHPCR) or->length('a.foo')
(PHPCRLengthInterface
).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.
but why did you assume in the error that the method is being called for an ordering?
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.
in other words. i am still unsure if your changes make sense or just please the unit tests
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.
in my original commit we only checked for nodetype and associations inside the foreach for orderings:
5fa4e2c#diff-0f74c7373c7c111b598f851ef2957d0eR760
I am still not sure where the issue was with that version of the PR
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.
In your version you call
->getField
in the ordering walker. But->getField
only applies to theOperandDynamicField
node, not to any of the other DynamicOperands (length, lowercase, localname) etc.The error message should be about not being able to use the nodename (or an association) field as a dynamic operand.
In fact we should probably just simply check to see if the field is mapped to a something which corresponds to a PHPCR property?
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.
yeah .. for ordering it needs to be a "simple name", ie. a property.
for filtering it should additionally not allow node names and associations.
for reference associations i am actually not quite sure if we should not allow equality conditions.
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.
So by having this here we also prevent:
because the user should be doing
I think.
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.
I have pushed an improvement for this.