lighthouse
lighthouse copied to clipboard
Batchloading BelongsTo repeats last retrieved model
When retrieving a nested (3 relations deep) belongsTo relation the last retrived model of that relation gets placed for all belongsTo relations.
This is solved by desabling batchloading.
The belongs to relations is accessed via two has many relations

Lighthouse Version: 5.39.2
Please try and add a failing test case to https://github.com/nuwave/lighthouse/blob/master/tests/Integration/Schema/Directives/BelongsToDirectiveTest.php
I just spent a couple of hours debugging the same error.
In my case, the problem turned out to be, that I'm using a model which has a string as primary key. I had not added following to the model:
public $incrementing = false;
As soon as I added this, it solved the problem.
From your example @MissaelAnda, it looks like the child model might be using a string as primary key as well.
But it might just be caused by modifier.id being typed as a string in your schema?
I'm loading the parent model from a MySQL view, and because of this I had not given the model's configuration much thought, since I won't ever be doing any writes to the database with the given model. I assume the fact that I'm using a view instead of a table doesn't really matter for this scenario, but I haven't tested.
Since I opened this issue we obfuscated the db's ID and now we're using UUIDs as public IDs, since we made that change the problem disappear so it probably was a mismatch type in the schema as @alberthaff said, closing the issue.