Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1bef2de

Browse files
Merge 5.2 into 5.x (#3331)
2 parents 730a2ac + 5832007 commit 1bef2de

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

‎src/Query/Builder.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,6 @@ public function update(array $values, array $options = [])
783783
unset($values[$key]);
784784
}
785785

786-
// Since "id" is an alias for "_id", we prevent updating it
787-
foreach ($values as $fields) {
788-
if (array_key_exists('id', $fields)) {
789-
throw new InvalidArgumentException('Cannot update "id" field.');
790-
}
791-
}
792-
793786
return $this->performUpdate($values, $options);
794787
}
795788

‎tests/Ticket/GH3326Test.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MongoDB\Laravel\Tests\Ticket;
6+
7+
use MongoDB\Laravel\Eloquent\Model;
8+
use MongoDB\Laravel\Tests\TestCase;
9+
10+
/**
11+
* @see https://github.com/mongodb/laravel-mongodb/issues/3326
12+
* @see https://jira.mongodb.org/browse/PHPORM-309
13+
*/
14+
class GH3326Test extends TestCase
15+
{
16+
public function testCreatedEventCanSafelyCallSave(): void
17+
{
18+
$model = new GH3326Model();
19+
$model->foo = 'bar';
20+
$model->save();
21+
22+
$fresh = $model->fresh();
23+
24+
$this->assertEquals('bar', $fresh->foo);
25+
$this->assertEquals('written-in-created', $fresh->extra);
26+
}
27+
}
28+
29+
class GH3326Model extends Model
30+
{
31+
protected $connection = 'mongodb';
32+
protected $collection = 'test_gh3326';
33+
protected $guarded = [];
34+
35+
protected static function booted(): void
36+
{
37+
static::created(function ($model) {
38+
$model->extra = 'written-in-created';
39+
$model->saveQuietly();
40+
});
41+
}
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /