Skip to content

Commit d26aba8

Browse files
committed
update callable scenario for action create
1 parent 0d0f005 commit d26aba8

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/actions/CreateAction.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ class CreateAction extends JsonApiAction
5858
* It must return a string representing the scenario to be assigned to the model before it is validated and saved.
5959
* The signature of the callable should be as follows,
6060
* ```php
61-
* function ($action, $model = null) {
61+
* function ($action, $model) {
6262
* // $model is the requested model instance.
63-
* // If null, it means no specific model (e.g. CreateAction)
6463
* }
6564
* ```
6665
*/
@@ -110,9 +109,10 @@ public function run()
110109
}
111110

112111
/* @var $model \yii\db\ActiveRecord */
113-
$model = new $this->modelClass([
114-
'scenario' => is_callable($this->scenario) ? call_user_func($this->scenario, $this->id) : $this->scenario,
115-
]);
112+
$model = new $this->modelClass();
113+
$model->setScenario(is_callable($this->scenario) ?
114+
call_user_func($this->scenario, $this->id, $model) : $this->scenario
115+
);
116116
RelationshipManager::validateRelationships($model, $this->getResourceRelationships(), $this->allowedRelations);
117117
$model->load($this->getResourceAttributes(), '');
118118
if ($this->isParentRestrictionRequired()) {

src/actions/DeleteAction.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ class DeleteAction extends JsonApiAction
2929
* It must return a string representing the scenario to be assigned to the model before it is validated and saved.
3030
* The signature of the callable should be as follows,
3131
* ```php
32-
* function ($action, $model = null) {
32+
* function ($action, $model) {
3333
* // $model is the requested model instance.
34-
* // If null, it means no specific model (e.g. CreateAction)
3534
* }
3635
* ```
3736
*/

src/actions/UpdateAction.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ class UpdateAction extends JsonApiAction
5959
* It must return a string representing the scenario to be assigned to the model before it is validated and updated.
6060
* The signature of the callable should be as follows,
6161
* ```php
62-
* function ($action, $model = null) {
62+
* function ($action, $model) {
6363
* // $model is the requested model instance.
64-
* // If null, it means no specific model (e.g. CreateAction)
6564
* }
6665
* ```
6766
*/

0 commit comments

Comments
 (0)