Closed
Description
I have Project model morph one to Document model
app/Models/Project.php
/**
* Project morph one contract document
*
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
*/
public function contractDocument()
{
return $this->morphOne(Document::class, 'documentable');
}
app/Models/Document.php
/**
* Document morph to documentable
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function documentable()
{
return $this->morphTo();
}
with relation registration in adapter
app/JsonApi/v1/Projects/Adapter.php
/**
* Project morph one contract document
*
* @return \CloudCreativity\LaravelJsonApi\Eloquent\HasOne
*/
protected function contractDocument()
{
return $this->hasOne();
}
When creating project via [POST] https://api.test/v1/projects
with payload
{
"data": {
"type": "projects",
"attributes": {
"name": "1st project",
},
"relationships": {
"contractDocument": {
"data": {
"type": "documents",
"id": "90"
}
}
}
}
}
I got an internal server error (500) when creating record with message
JSON API relation HasOne cannot be used for an Eloquent MorphOne relation
laravel-json-api/src/Eloquent/Concerns/QueriesRelations.php
Lines 35 to 55 in 71fc1a8
Do you have any idea?
Metadata
Metadata
Assignees
Labels
No labels