Skip to content

Commit a8c3791

Browse files
committed
Refactor, extend tests
1 parent 30fa2dd commit a8c3791

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,17 @@ protected function compileJsonPatch($column, $value)
200200
*/
201201
protected function compileUpdateColumns(Builder $query, array $values)
202202
{
203-
$groups = collect($this->groupJsonColumnsForUpdate($values))->map(function ($value, $key) {
204-
$column = last(explode('.', $key));
205-
206-
return $this->wrap($column).' = '.$this->compileJsonPatch($column, $value);
207-
});
203+
$groups = $this->groupJsonColumnsForUpdate($values);
208204

209205
return collect($values)->reject(function ($value, $key) {
210206
return $this->isJsonSelector($key);
211-
})->map(function ($value, $key) {
207+
})->merge($groups)->map(function ($value, $key) use ($groups) {
212208
$column = last(explode('.', $key));
213209

214-
return $this->wrap($column).' = '.$this->parameter($value);
215-
})->merge($groups)->implode(', ');
210+
$updateSql = isset($groups[$key]) ? $this->compileJsonPatch($column, $value) : $this->parameter($value);
211+
212+
return $this->wrap($column).' = '.$updateSql;
213+
})->implode(', ');
216214
}
217215

218216
/**

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,13 +2557,14 @@ public function testSQLiteUpdateWrappingNestedJsonArray()
25572557
$builder->getConnection()->shouldReceive('update')
25582558
->with('update "users" set "group_id" = 45, "created_at" = ?, "options" = json_patch(ifnull("options", json(\'{}\')), json(?))', [
25592559
new DateTime('2019-08-06'),
2560-
json_encode(['name' => 'Taylor', 'security' => ['2fa' => false, 'presets' => ['laravel', 'vue']]]),
2560+
json_encode(['name' => 'Taylor', 'security' => ['2fa' => false, 'presets' => ['laravel', 'vue']], 'sharing' => ['twitter' => 'username']]),
25612561
]);
25622562

25632563
$builder->from('users')->update([
25642564
'options->name' => 'Taylor',
2565-
'options->security' => ['2fa' => false, 'presets' => ['laravel', 'vue']],
25662565
'group_id' => new Raw('45'),
2566+
'options->security' => ['2fa' => false, 'presets' => ['laravel', 'vue']],
2567+
'options->sharing->twitter' => 'username',
25672568
'created_at' => new DateTime('2019-08-06'),
25682569
]);
25692570
}

0 commit comments

Comments
 (0)