Skip to content

Commit 924ada5

Browse files
committed
ability of composite primary key using
1 parent 028f382 commit 924ada5

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

DOCUMENTATION.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ DeleteMultipleAction Class
4343

4444
- `modelClass`: *string*, the model class name. This property must be set.
4545

46-
- `primaryKey`: *string*, the primary key name.
47-
4846
- `beforeDeleteCallback`: *callable*, a callback that will be called after deleting selected items. The signature of the callback should be as `function ($action)`, where `$action` is the current action object.
4947

5048
- `afterDeleteCallback`: *callable*, a callback that will be called after deleting selected items. The signature of the callback should be as `function ($action)`, where `$action` is the current action object.
@@ -57,4 +55,4 @@ DeleteMultipleAction Class
5755

5856
[renderTagAttributes()]:http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail
5957
[dropDownList()]:http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#dropDownList()-detail
60-
[t()]:http://www.yiiframework.com/doc-2.0/yii-baseyii.html#t()-detail
58+
[t()]:http://www.yiiframework.com/doc-2.0/yii-baseyii.html#t()-detail

DeleteMultipleAction.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use yii\base\InvalidConfigException;
77
use yii\web\NotFoundHttpException;
88
use yii\helpers\Url;
9+
use yii\helpers\Json;
910

1011
/**
1112
* DeleteMultipleAction deletes the selected rows of the GridView.
@@ -18,10 +19,6 @@ class DeleteMultipleAction extends Action
1819
* @var string the model class name. This property must be set.
1920
*/
2021
public $modelClass;
21-
/**
22-
* @var string the primary key name.
23-
*/
24-
public $primaryKey = 'id';
2522
/**
2623
* @var callable a callback that will be called before deleting selected items.
2724
*
@@ -76,7 +73,10 @@ public function run()
7673

7774
/* @var $modelClass \yii\db\ActiveRecord */
7875
$modelClass = $this->modelClass;
79-
$models = $modelClass::findAll([$this->primaryKey => Yii::$app->request->post('ids')]);
76+
$models = [];
77+
foreach (Yii::$app->request->post('ids') as $id) {
78+
$models = array_merge($models, $modelClass::findAll(Json::decode($id)));
79+
}
8080
if (empty($models)) {
8181
throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
8282
} else {

Widget.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected function renderElements($template)
233233
form.append('<input type=\"hidden\" name=' + csrfParam + ' value=' + csrfToken + ' />');
234234
}
235235
$.each(ids, function(index, id) {
236-
form.append('<input type=\"hidden\" name=\"' + (options.getAttribute('name') ? options.getAttribute('name') : 'ids') + '[]\" value=' + id + ' />');
236+
form.append('<input type=\"hidden\" name=\"' + (options.getAttribute('name') ? options.getAttribute('name') : 'ids') + '[]\" value=' + JSON.stringify(id) + ' />');
237237
});
238238
form.appendTo('body').submit();
239239
}

0 commit comments

Comments
 (0)