Skip to content

Commit 940c183

Browse files
Firetawnyowlnekufa
authored andcommitted
set_indexes fix
1 parent f1c7fdb commit 940c183

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/Space.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ public function setIndexes(array $indexes)
352352
foreach ($indexes as $n => $index) {
353353
$indexes[$n]['fields'] = [];
354354
foreach ($index['parts'] as $part) {
355-
$indexes[$n]['fields'][] = $this->fields[$part[0]];
355+
if (array_key_exists('field', $part)){
356+
$indexes[$n]['fields'][] = $this->fields[$part['field']];
357+
} else {
358+
$indexes[$n]['fields'][] = $this->fields[$part[0]];
359+
}
356360
}
357361
}
358362
$this->indexes = $indexes;

tests/MapperTest.php

+49
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
use Monolog\Handler\StreamHandler;
88
use Monolog\Logger;
99
use PHPUnit\Framework\TestCase;
10+
use ReflectionProperty;
1011
use Tarantool\Client\Client;
1112
use Tarantool\Mapper\Mapper;
1213
use Tarantool\Mapper\Pool;
14+
use Tarantool\Mapper\Space;
1315
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1416

1517
class MapperTest extends TestCase
@@ -49,6 +51,53 @@ public function testCache()
4951
$this->assertCount($freshCounter - 4, $this->middleware->data);
5052
}
5153

54+
// public function testSpaceGetFormat()
55+
// {
56+
57+
// }
58+
59+
public function testDifferentIndexPartConfiguration()
60+
{
61+
$mapper = $this->createMapper();
62+
foreach ($mapper->find('_vspace') as $space) {
63+
if ($space['id'] >= 512) {
64+
$mapper->getSpace($space['id'])->drop();
65+
}
66+
}
67+
68+
$tester = $mapper->createSpace('tester');
69+
$tester->addProperty('id', 'unsigned');
70+
$tester->addProperty('name', 'string');
71+
72+
$tester->addIndex(['name'], ['name'=>'first']);
73+
74+
$mapper->client->call("box.space.tester:create_index", 'second', [
75+
'parts' => ['name']
76+
]);
77+
78+
$indexSpace = $mapper->getSpace('_index');
79+
80+
$third = [
81+
'id' => $tester->getId(),
82+
'iid' => count($mapper->find('_vindex', ['id' => $tester->getId()])) + 1,
83+
'name' => 'third',
84+
'opts' => ['unique' => false],
85+
'type' => 'tree',
86+
'parts' => [
87+
['field'=> 1, 'type' => 'str']
88+
]
89+
];
90+
91+
$mapper->client->call("box.space._index:insert", $indexSpace->getTuple($third));
92+
93+
$property = new ReflectionProperty(Space::class, 'indexes');
94+
$property->setAccessible(true);
95+
$indexes = $property->getValue($tester);
96+
97+
$this->assertSame($indexes[1]['fields'], $indexes[2]['fields']);
98+
$this->assertSame($indexes[1]['fields'], $indexes[3]['fields']);
99+
}
100+
52101
public function testLua()
53102
{
54103
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)