-
-
Notifications
You must be signed in to change notification settings - Fork 509
Fix query preparation when querying for referenced object #1481
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
Conversation
return array($fieldName, $this->dm->createDBRef($value, $mapping)); | ||
$dbRef = $this->dm->createDBRef($value, $mapping); | ||
|
||
if (! is_array($dbRef)) { |
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 had to stop for a moment and think about why such a check is here, the original check on strategy is way more readable. Also it will prevent us from hitting an edge case when id might be an array
As a starter I'm sorry for introducing the bug, I admit that I haven't thought about indexes at all back then :)
If this is only issue of what's |
|
||
if (! is_array($dbRef)) { | ||
return array($fieldName, $dbRef); | ||
} elseif ($mapping['type'] == 'many') { |
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 should be ===
I thought about that as well - just wasn't sure which route we want to take. I'll have to see how we can accomodate that without creating a weird return type, but if at all possible I'll do exactly that. Thanks for the input! 👍 |
e3b1a42
to
ab968ca
Compare
@malarzm udpated PR as per your suggestion. |
list($key, $value) = $this->prepareQueryElement($nextObjectProperty, $value, $nextTargetClass, $prepareValue); | ||
$fieldNames = $this->prepareQueryElement($nextObjectProperty, $value, $nextTargetClass, $prepareValue); | ||
|
||
return array_map(function ($preparedTupel) use ($fieldName) { |
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.
Nitpicking, but you have a typo in var name ;)
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.
It's not a typo, it's German! 😁
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 the germanization of Doctrine begins, one variable at a time? :P
ab968ca
to
afe12fa
Compare
Thanks \o/ |
This PR fixes an issue introduced with #1363 when running queries like
$dm->getRepository(User::class)->findOneBy(['account' => $account]);
, with$account
being a referenced document. When using thereferences
method of the query builder, the query array looks like this:When using
includesReferenceTo
which is made for@ReferenceMany
mappings, the result looks like this:However, the implementation in the DocumentPersister always yielded a full DBRef object:
This caused issues when forcing queries to be covered by indexes (through the
notablescan
option in MongoDB), since it would require two different kinds of indexes on a reference: one on the entire DBRef object to cover queries like created through the DocumentPersister and another index on the$id
field of the reference to cover queries created by the query builder in combination withreferences
.This solution tries to apply the same logic applied by the query builder to the documents in question. The only exception are
@ReferenceOne
fields without a target document set. These would produce the following query array:This is not possible at this time since the DocumentPersister always assumes that a single field has exactly one value. For now, the PR includes a failing test case for this, as the DocumentPersister excludes
@ReferenceOne
fields without targetDocument set.