Skip to content

Commit

Permalink
primary index for id field only
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Oct 10, 2024
1 parent 2b627b7 commit c8a2ac3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Space.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function addProperty(string $name, string $type, array $config = [])
$this->format[] = $config;
$this->mapper->client->call("box.space.$this->name:format", $this->format);

if (count($this->fields) == 1) {
if (count($this->fields) == 1 && $this->fields == ['id']) {
$this->addIndex($this->fields, [
'unique' => true,
]);
Expand Down
12 changes: 12 additions & 0 deletions tests/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,22 @@ public function testClassBased()
$this->assertEquals($row, $mapper->findOne('constructor'));
}

public function testIdleField()
{
$mapper = $this->createMapper();
$tester = $mapper->createSpace('tester');
$tester->addProperty('name', 'string');
$tester->addProperty('idle', 'unsigned');
$this->assertCount(0, $mapper->find('_index', ['id' => $tester->getId()]));
}

public function testUpdateStringPrimaryKey()
{
$mapper = $this->createMapper();
$userdata = $mapper->createSpace('userdata');
$userdata->addProperty('key', 'string');
$userdata->addProperty('value', 'string');
$userdata->addIndex(['key']);

$name = $userdata->create(['key' => 'name', 'value' => 'nekufa']);
$mapper->update('userdata', $name, ['value' => 'Dmitry Krokhin']);
Expand Down Expand Up @@ -223,6 +233,8 @@ public function testCreateRow()
$tester = $mapper->createSpace('tester');
$tester->addProperty('name', 'string');
$tester->addProperty('id', 'unsigned');
$tester->addIndex(['name']);

$testRow = ['name' => 'Vasiliy'];
$testRow2 = ['name' => 'Ivan'];
$tester->create($testRow);
Expand Down

0 comments on commit c8a2ac3

Please sign in to comment.