{"record":{"id":"5b2727f47db5c0a9","repo":"flarum/framework","slug":"relationship-does-not-include-data-key","errorCode":null,"errorMessage":"relationship does not include data key","messagePattern":"relationship does not include data key","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"framework/core/src/Api/Schema/Relationship/ToOne.php","lineNumber":29,"sourceCode":"\nuse Flarum\\Api\\Schema\\Concerns\\FlarumRelationship;\nuse Tobyz\\JsonApiServer\\Context;\nuse Tobyz\\JsonApiServer\\Exception\\BadRequestException;\nuse Tobyz\\JsonApiServer\\Exception\\Sourceable;\nuse Tobyz\\JsonApiServer\\Laravel\\Field\\ToOne as BaseToOne;\n\nclass ToOne extends BaseToOne\n{\n    use FlarumRelationship;\n\n    public function deserializeValue(mixed $value, Context $context): mixed\n    {\n        if ($this->deserializer) {\n            return ($this->deserializer)($value, $context);\n        }\n\n        if (! is_array($value) || ! array_key_exists('data', $value)) {\n            throw new BadRequestException('relationship does not include data key');\n        }\n\n        if ($value['data'] === null) {\n            return null;\n        }\n\n        if (count($this->collections) === 1) {\n            $value['data']['type'] ??= $this->collections[0];\n        }\n\n        try {\n            return $this->findResourceForIdentifier($value['data'], $context);\n        } catch (Sourceable $e) {\n            throw $e->prependSource(['pointer' => '/data']);\n        }\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Api/Schema/Relationship/ToOne.php#L11-L47","documentation":"Thrown in ToOne::deserializeValue when a client writes a to-one relationship whose JSON:API value is not an object containing a 'data' member. Flarum/tobyz-json-api-server requires relationship documents to be {data: ...}; anything else (string, number, missing 'data' key) cannot be interpreted as a resource identifier or null, so the request is rejected as a 400 Bad Request.","triggerScenarios":"Thrown at framework/core/src/Api/Schema/Relationship/ToOne.php:29 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send the relationship value as an object with a 'data' member, e.g. {\"data\": {\"type\": \"users\", \"id\": \"1\"}}","Use {\"data\": null} to clear the to-one relationship","Ensure the request body is valid JSON:API so 'data' parses as an array in PHP"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}