Skip to content

Conversation

@horstoeko
Copy link

@horstoeko horstoeko commented Sep 28, 2021

Hi,

I have the following situation:

Model Document --> 1:1 --> Model File --> 1:1 --> Model FileContent.

My model definition of my Document looks like

public function file(): HasOne
{
    return $this->hasOne(File::class);
}

public function filecontent(): HasOneThrough
{
    return $this->hasOneThrough(Filecontent::class, File::class);
}

I declared the following routes (routes/api.php):

  • Orion::resource('documents', DocumentController::class)
  • Orion::hasOneResource('documents', 'file', FileController::class)
  • Orion::hasOneThroughResource('documents', 'filecontent', FilecontentController::class)

These declarations result in the following routes:

| POST      | api/documents/{document}/file
| DELETE    | api/documents/{document}/file/{file?}
| PUT|PATCH | api/documents/{document}/file/{file?}
| GET|HEAD  | api/documents/{document}/file/{file?}
| POST      | api/documents/{document}/filecontent
| DELETE    | api/documents/{document}/filecontent/{filecontent?}
| GET|HEAD  | api/documents/{document}/filecontent/{filecontent?}
| PUT|PATCH | api/documents/{document}/filecontent/{filecontent?}

When I send the PATCH-Request to http://localhost/api/documents/50000/filecontent (where 50000 is the ID of my Document model), I get the following error response:

{
    "message": "Relation key is required, if relation type is not one-to-one",
    "exception": "InvalidArgumentException",
}

Please check, if my fix is okay for you (and save enough :-))

@alexzarbn
Copy link
Member

Hi @horstoeko,

Thank you for the PR! Merging ~

@alexzarbn alexzarbn merged commit 4716556 into tailflow:main Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants