Skip to content

Commit 5a479df

Browse files
committed
optimize code
1 parent 873b1ee commit 5a479df

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Model/Behavior/SequenceBehavior.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,17 @@ function ($connection) use ($table, $records, $config) {
287287
}
288288

289289
if (is_array($record)) {
290-
$entity = $table->newEntity();
291-
$record = $entity->set($record, ['guard' => false]);
290+
$record = $table->newEntity($record, [
291+
'fieldList' => array_keys($record),
292+
'accessibleFields' => [
293+
$table->primaryKey() => true
294+
]
295+
]);
292296
$record->isNew(false);
297+
$record->dirty($table->primaryKey(), false);
293298
}
294299

300+
$record->accessible($field);
295301
$record->set($field, $order++);
296302

297303
$r = $table->save(
@@ -405,7 +411,7 @@ protected function _sync($fields, $conditions, $scope = null)
405411
*
406412
* @param string $direction Whether to increment or decrement the field.
407413
*
408-
* @return Cake\Database\Expression\QueryExpression QueryExpression to modify the order field
414+
* @return \Cake\Database\Expression\QueryExpression QueryExpression to modify the order field
409415
*/
410416
protected function _getUpdateExpression($direction = '+')
411417
{

0 commit comments

Comments
 (0)