From c8a2ac3aff98840a34ee18e48f8a88b99098651d Mon Sep 17 00:00:00 2001 From: dmitry krokhin Date: Thu, 10 Oct 2024 14:40:07 +0300 Subject: [PATCH] primary index for id field only --- src/Space.php | 2 +- tests/MapperTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Space.php b/src/Space.php index 28e76d4..6f8e307 100644 --- a/src/Space.php +++ b/src/Space.php @@ -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, ]); diff --git a/tests/MapperTest.php b/tests/MapperTest.php index 48e7fa9..96a11f5 100644 --- a/tests/MapperTest.php +++ b/tests/MapperTest.php @@ -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']); @@ -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);