laravel-orion: Includes are broken in version 2.17.0
Since version 2.17.0 our “include” with a relation is broken. In version 2.16.0 this still works.
My test case:
$this->post('api/attachments/search?include=chatMessage,chatMessage.to,chatMessage.from')->assertOk();
This used to work, but now it gives an 500 status. It now throws an exception, while this works in the previous version. The exception:
{#4430
+"message": "Call to undefined method App\Models\Media::chatMessage.to()"
+"exception": "BadMethodCallException"
+"file": "<path>/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php"
... etc.
My Controller looks like this:
class AttachmentsController extends Controller
{
protected $model = Media::class;
public function includes(): array
{
return ['chatMessage', 'chatMessage.*'];
}
// ... etc
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (8 by maintainers)
I see that in the file
src/Drivers/Standard/RelationsResolver.phptherequestedRelationsmethod does not include the relation if it is posted.Changing line 44:
To:
Seems to resolve this issue.
I see that this is exactly the same as @jeroenqui described here 🙈
In my opinion this logic should not be broken, even if it’s an undocumented feature.
@alexzarbn When I use the “post” version of includes:
Endpoint: /api/tickets/search
Error 500
Call to undefined method App\\Models\\Customer::user()Even when I try this in my controller:
relations are not included.
Published a fix in v2.17.1. Could you please let me know, if the problem is resolved for all of your apps?
The following code in
src/Drivers/Standard/QueryBuildercan’t handle nested relations like
chatMessage.to