Skip to content

Commit 948c3bb

Browse files
committed
[bugfix] Fixed can not save bug when model's primary key is multiple.
If the model's primary key is multiple: ['lang_id', 'code] The $pk will be an array of primary key combined data, so we can use it directly to find the data
1 parent 9144b9f commit 948c3bb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

EditableAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function run()
5656
$class = $this->modelClass;
5757
$pk = Yii::$app->request->post('pk');
5858
$attribute = Yii::$app->request->post('name');
59-
//For attributes with format - relationName.attributeName
59+
//For attributes with format - relationName.attributeName
6060
if (strpos($attribute, '.')) {
6161
$attributeParts = explode('.', $attribute);
6262
$attribute = array_pop($attributeParts);
@@ -69,7 +69,7 @@ public function run()
6969
throw new BadRequestHttpException("Value cannot be empty.");
7070
}
7171
/** @var \Yii\db\ActiveRecord $model */
72-
$model = $class::findOne([$this->pkColumn => $pk]);
72+
$model = $class::findOne(is_array($pk) ? $pk : [$this->pkColumn => $pk]);
7373
if (!$model) {
7474
if ($this->forceCreate) { // only useful for models with one editable attribute or no validations
7575
$model = new $class;
@@ -93,4 +93,4 @@ public function run()
9393
}
9494
}
9595

96-
}
96+
}

0 commit comments

Comments
 (0)