laravel / nova-issues

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relation not set when updating a`BelongsTo` with limited `$relatableSearchResults` set

Livijn opened this issue · comments

Description:

I have a BelongsTo field but my BelongsTo relation is not set when updating.

// App\Nova\Article
BelongsTo::make('User', 'user', User::class)
    ->searchable(),

// App\Nova\User
public static $relatableSearchResults = 200;

When updating an Article the User isn't set so I have to manually search for the User again:

image

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

Hey there,

We're closing this issue because it's inactive, already solved, old, or not relevant anymore. Feel free to open up a new issue if you're still experiencing this problem.

Do you have a default repo with laravel + nova that I can fork? @crynobone

I wasn't able to reproduce this in a new repo. However, this issue is still occurring for me. I am trying to debug it but I'd like for you to point me in a direction.

This is the URL which seems correct comparing to the other repo that is working:

https://xxx.test/nova-api/insurances/associatable/user?current=15345&first=true&search=&withTrashed=false&resourceId=109&viaResource=&viaResourceId=&viaRelationship=&component=belongsto.belongs-to-field.user&dependsOn=eyJ1c2VyIjoiVGhcdTAwZTlyXHUwMGU4emUgTFx1MDBmNm5uaGFtbWFyIn0%3D&editing=true&editMode=update

However, the response is just a list of incorrect users:

{
  "resources": [
    {
      "display": "XXX",
      "subtitle": "xxx",
      "value": 153898
    },
    {
      "display": "XXX",
      "subtitle": "xxx",
      "value": 153897
    }
    // ...
  ],
  "softDeletes": true,
  "withTrashed": false
}

This happens for all my BelongsTo-fields. Using Telescope I can see that it actually does an SQL-query for the correct User ID:

select * from users where users.id = '15345' limit 1

It's the $request->first === 'true' in the buildAssociatableQuery-function that causes the bug. When dumping the $request->first I received a boolean, not a string. This was caused by a middleware I have called ConvertStringBooleans.