lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Batchloading BelongsTo repeats last retrieved model

Open MissaelAnda opened this issue 3 years ago • 1 comments
trafficstars

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

imagen

Lighthouse Version: 5.39.2

MissaelAnda avatar Feb 11 '22 18:02 MissaelAnda

Please try and add a failing test case to https://github.com/nuwave/lighthouse/blob/master/tests/Integration/Schema/Directives/BelongsToDirectiveTest.php

spawnia avatar Feb 14 '22 10:02 spawnia

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.

alberthaff avatar Oct 29 '22 17:10 alberthaff

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.

MissaelAnda avatar Oct 29 '22 18:10 MissaelAnda