Skip to content

Commit 0eed736

Browse files
committed
PHPORM-311 Fix Update of numeric field name
1 parent 3aa95be commit 0eed736

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/Eloquent/Builder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ protected function addUpdatedAtColumn(array $values)
309309
}
310310

311311
$column = $this->model->getUpdatedAtColumn();
312-
$values = array_merge(
312+
$values = array_replace(
313313
[$column => $this->model->freshTimestampString()],
314314
$values,
315315
);

tests/Ticket/GH3335Test.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Laravel\Tests\Ticket;
6+
7+
use MongoDB\Laravel\Tests\Models\Location;
8+
use MongoDB\Laravel\Tests\TestCase;
9+
10+
/** @see https://github.com/mongodb/laravel-mongodb/discussions/3335 */
11+
class GH3335Test extends TestCase
12+
{
13+
public function tearDown(): void
14+
{
15+
Location::truncate();
16+
17+
parent::tearDown();
18+
}
19+
20+
public function testNumericalFieldName()
21+
{
22+
$model = new Location();
23+
$model->id = 'foo';
24+
$model->save();
25+
26+
$model = Location::find('foo');
27+
$model->{'38'} = 'PHP';
28+
$model->save();
29+
30+
$model = Location::find('foo');
31+
self::assertSame('PHP', $model->{'38'});
32+
}
33+
}

0 commit comments

Comments
 (0)