Skip to content

Commit 0d4c2f0

Browse files
author
Maciej Malarz
committed
Merge pull request #1554
2 parents e96bfba + 81b6ff7 commit 0d4c2f0

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

lib/Doctrine/ODM/MongoDB/Query/Expr.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function references($document)
9090
}
9191

9292
foreach ($keys as $key => $value) {
93-
$this->query[$this->currentField . '.$' . $key] = $dbRef['$' . $key];
93+
$this->query[$mapping['name'] . '.$' . $key] = $dbRef['$' . $key];
9494
}
9595
}
9696
} else {
@@ -128,7 +128,7 @@ public function includesReferenceTo($document)
128128
}
129129

130130
foreach ($keys as $key => $value) {
131-
$this->query[$this->currentField]['$elemMatch']['$' . $key] = $dbRef['$' . $key];
131+
$this->query[$mapping['name']]['$elemMatch']['$' . $key] = $dbRef['$' . $key];
132132
}
133133
}
134134
} else {

tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ public function testReferencesUsesMinimalKeys()
206206
->will($this->returnValue($expected));
207207
$class->expects($this->once())
208208
->method('getFieldMapping')
209-
->will($this->returnValue(array('targetDocument' => 'Foo')));
209+
->will($this->returnValue(array('targetDocument' => 'Foo', 'name' => 'foo')));
210210

211211
$expr = new Expr($dm);
212212
$expr->setClassMetadata($class);
213-
$expr->field('foo')->references(new \stdClass());
213+
$expr->field('bar')->references(new \stdClass());
214214

215215
$this->assertEquals($expected, $expr->getQuery(), '->references() uses just $id if a targetDocument is set');
216216
}
@@ -239,11 +239,11 @@ public function testReferencesUsesAllKeys()
239239
->will($this->returnValue($expected));
240240
$class->expects($this->once())
241241
->method('getFieldMapping')
242-
->will($this->returnValue(array()));
242+
->will($this->returnValue(array('name' => 'foo')));
243243

244244
$expr = new Expr($dm);
245245
$expr->setClassMetadata($class);
246-
$expr->field('foo')->references(new \stdClass());
246+
$expr->field('bar')->references(new \stdClass());
247247

248248
$this->assertEquals($expected, $expr->getQuery(), '->references() uses all keys if no targetDocument is set');
249249
}
@@ -272,11 +272,11 @@ public function testReferencesUsesSomeKeys()
272272
->will($this->returnValue($expected));
273273
$class->expects($this->once())
274274
->method('getFieldMapping')
275-
->will($this->returnValue(array('storeAs' => ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF)));
275+
->will($this->returnValue(array('storeAs' => ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF, 'name' => 'foo')));
276276

277277
$expr = new Expr($dm);
278278
$expr->setClassMetadata($class);
279-
$expr->field('foo')->references(new \stdClass());
279+
$expr->field('bar')->references(new \stdClass());
280280

281281
$this->assertEquals($expected, $expr->getQuery(), '->references() uses some keys if storeAs=dbRef is set');
282282
}

0 commit comments

Comments
 (0)