diff --git a/src/Command/Database/Insert.php b/src/Command/Database/Insert.php index 00f4e324..13c8b8a1 100644 --- a/src/Command/Database/Insert.php +++ b/src/Command/Database/Insert.php @@ -111,10 +111,11 @@ public function execute(): void $returning = $this->mapper->mapColumns($returningFields); // Array of [field name => column name] $returning = \array_combine(\array_keys($returningFields), \array_keys($returning)); - // TODO remove: - $returning = \array_slice($returning, 0, 1); // only one returning field is supported - $insert->returning(...array_values($returning)); + // TODO replace: + // $insert->returning(...\array_values($returning)); + $insert->returning(\array_values($returning)[0]); + $insertID = $insert->run(); if (count($returning) === 1) { @@ -123,9 +124,8 @@ public function execute(): void $field, $this->mapper === null ? $insertID : $this->mapper->cast([$field => $insertID])[$field], ); - } else { - // todo multiple returning } + // todo multiple returning } else { $insertID = $insert->run(); diff --git a/src/SchemaInterface.php b/src/SchemaInterface.php index 7ef10358..4cf69a39 100644 --- a/src/SchemaInterface.php +++ b/src/SchemaInterface.php @@ -38,7 +38,6 @@ interface SchemaInterface public const GENERATED_PHP_INSERT = 2; // generated by PHP code on insert like uuid public const GENERATED_PHP_UPDATE = 4; // generated by PHP code on update like time - /** * Return all roles defined within the schema. */ diff --git a/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php b/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php index 110b98a3..dab22c65 100644 --- a/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php +++ b/tests/ORM/Functional/Driver/Common/Integration/Case321/CaseTest.php @@ -4,7 +4,6 @@ namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321; -use Cycle\ORM\Select; use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest; use Cycle\ORM\Tests\Functional\Driver\Common\Integration\IntegrationTestTrait; use Cycle\ORM\Tests\Traits\TableTrait; diff --git a/tests/ORM/Unit/Command/InsertCommandTest.php b/tests/ORM/Unit/Command/InsertCommandTest.php index 266e5f63..a29ffc1d 100644 --- a/tests/ORM/Unit/Command/InsertCommandTest.php +++ b/tests/ORM/Unit/Command/InsertCommandTest.php @@ -142,6 +142,11 @@ public function testCommandWithReturningInterfaceShouldUseIt() ->with(['foo' => 'baaar']) ->andReturn(['baz' => 'bar']); + $this->mapper->shouldReceive('mapColumns') + ->once() + ->with(['id' => 'foo_id']) + ->andReturn(['foo_id' => 'foo_id']); + $this->mapper->shouldReceive('cast') ->once() ->with(['id' => 234])