Skip to content

Commit c8a2ac3

Browse files
committed
primary index for id field only
1 parent 2b627b7 commit c8a2ac3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Space.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function addProperty(string $name, string $type, array $config = [])
7777
$this->format[] = $config;
7878
$this->mapper->client->call("box.space.$this->name:format", $this->format);
7979

80-
if (count($this->fields) == 1) {
80+
if (count($this->fields) == 1 && $this->fields == ['id']) {
8181
$this->addIndex($this->fields, [
8282
'unique' => true,
8383
]);

tests/MapperTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,22 @@ public function testClassBased()
4848
$this->assertEquals($row, $mapper->findOne('constructor'));
4949
}
5050

51+
public function testIdleField()
52+
{
53+
$mapper = $this->createMapper();
54+
$tester = $mapper->createSpace('tester');
55+
$tester->addProperty('name', 'string');
56+
$tester->addProperty('idle', 'unsigned');
57+
$this->assertCount(0, $mapper->find('_index', ['id' => $tester->getId()]));
58+
}
59+
5160
public function testUpdateStringPrimaryKey()
5261
{
5362
$mapper = $this->createMapper();
5463
$userdata = $mapper->createSpace('userdata');
5564
$userdata->addProperty('key', 'string');
5665
$userdata->addProperty('value', 'string');
66+
$userdata->addIndex(['key']);
5767

5868
$name = $userdata->create(['key' => 'name', 'value' => 'nekufa']);
5969
$mapper->update('userdata', $name, ['value' => 'Dmitry Krokhin']);
@@ -223,6 +233,8 @@ public function testCreateRow()
223233
$tester = $mapper->createSpace('tester');
224234
$tester->addProperty('name', 'string');
225235
$tester->addProperty('id', 'unsigned');
236+
$tester->addIndex(['name']);
237+
226238
$testRow = ['name' => 'Vasiliy'];
227239
$testRow2 = ['name' => 'Ivan'];
228240
$tester->create($testRow);

0 commit comments

Comments
 (0)