Skip to content

Commit 11031ec

Browse files
committed
index finder fixed
1 parent 4604533 commit 11031ec

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/Space.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,18 @@ public function castIndex($params)
274274

275275
public function getIndexValues($indexId, $params)
276276
{
277-
$index = $this->getIndexes()[$indexId];
278-
$format = $this->getFormat();
277+
$index = null;
278+
foreach($this->getIndexes() as $candidate) {
279+
if($candidate->iid == $indexId) {
280+
$index = $candidate;
281+
break;
282+
}
283+
}
284+
if(!$index) {
285+
throw new Exception("Undefined index: $indexId");
286+
}
279287

288+
$format = $this->getFormat();
280289
$values = [];
281290
foreach($index->parts as $part) {
282291
$name = $format[$part[0]]['name'];

tests/MapperTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@
77

88
class MapperTest extends TestCase
99
{
10+
public function testIndexRemoved()
11+
{
12+
$mapper = $this->createMapper();
13+
$this->clean($mapper);
14+
15+
$mapper->getSchema()
16+
->createSpace('tester', [
17+
'id' => 'unsigned',
18+
'name1' => 'str',
19+
'name2' => 'str',
20+
])
21+
->addIndex('id')
22+
->addIndex('name1')
23+
->addIndex('name2')
24+
->removeIndex('name1');
25+
26+
$mapper->create('tester', [
27+
'id' => 1,
28+
'name1' => 'q',
29+
'name2' => 'w'
30+
]);
31+
32+
$mapper = $this->createMapper();
33+
$this->assertNotNull($mapper->findOne('tester', ['name2' => 'w']));
34+
}
35+
1036
public function testCasting()
1137
{
1238
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)