Skip to content

Commit

Permalink
scalar id support
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bretterklieber committed May 7, 2021
1 parent 8883fb5 commit 44abf5d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Stk/MongoDB/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function update(
}

if ($criteria === null) {
$criteria = ['_id' => new ObjectId($row->get('_id'))];
$criteria = ['_id' => is_string($row->get('_id')) ? new ObjectId($row->get('_id')) : $row->get('_id')];
}

$this->debug(__METHOD__ . ':' . $this->_collection->getCollectionName() . ':' . print_r($criteria,
Expand Down
27 changes: 27 additions & 0 deletions test/unit/Stk/MongoDB/ConntectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,33 @@ public function testBuildValueSetWithPrefix(): void
], $set);
}

public function testUpdateWithIntId(): void
{
$id = 234;
$row = new Record([
'_id' => $id,
'foo' => 'bar'
]);

$fields = [
'$set' => [
'alice' => 'bob'
]
];

$this->collection->expects($this->once())->method('updateOne')->with(
['_id' => $id],
[
'$set' => [
'foo' => 'bar',
'alice' => 'bob'
]
],
[]
);
$this->connector->update($row, $fields);
}

// insert

public function testInsert(): void
Expand Down

0 comments on commit 44abf5d

Please sign in to comment.