Skip to content

Commit 15c1e3b

Browse files
committed
When creating a resource, set the context model prior to field validation
Otherwise it is impossible for the fields to know what kind of model is being created
1 parent 480d8de commit 15c1e3b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to
88

99
## [Unreleased]
1010

11+
### Fixed
12+
13+
- When creating a resource, set the context model prior to field validation
14+
1115
## [1.0.0-beta.1] - 2023-09-24
1216

1317
### Added

src/Endpoint/Create.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ public function handle(Context $context): ?ResponseInterface
5151

5252
$data = $this->parseData($context);
5353

54+
$context = $context->withModel($model = $resource->newModel($context));
55+
5456
$this->assertFieldsValid($context, $data);
5557
$this->fillDefaultValues($context, $data);
5658
$this->deserializeValues($context, $data);
5759
$this->assertDataValid($context, $data, true);
58-
59-
$context = $context->withModel($model = $resource->newModel($context));
60-
6160
$this->setValues($context, $data);
6261

6362
$context = $context->withModel($model = $resource->create($model, $context));

0 commit comments

Comments
 (0)