sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

Incorrect eager loading on non singular relation

Open vincekieft opened this issue 2 years ago • 4 comments

Version: SQLBoiler v4.14.1 DB: mysql 8

Scenario: I have the following data that is looped through when eager loading: image

This (by sqlboiler generated) code appends relations to non singular entity: image

But the break on line 1245 causes the second (identical) item of slice to not have set relations. The resulting struct now doesn't have any SetVariationSets set.

What can I do to resolve this?

Another ticket that is still open and faced the exact same issue: https://github.com/volatiletech/sqlboiler/issues/457

vincekieft avatar Apr 09 '23 01:04 vincekieft

When I remove the break from the generated code the relations are set but I can see how the foreign.R.SetVariation keeps getting overwritten to the last local. Besides that manually changing the generated code ofc is a no go

vincekieft avatar Apr 09 '23 01:04 vincekieft

I am not sure when I'll be able to take a good look at this. In the meantime, if you can send in a PR to fix, that will be appreciated.

stephenafamo avatar Apr 13 '23 11:04 stephenafamo

I cannot send in a PR, I dont know how to fix this. Dont know this codebase

vincekieft avatar Apr 18 '23 21:04 vincekieft

I am also running into this problem. In my case I have a M-N-1 relationship chain and the "1"s aren't distributing over the "N"s properly. This seems to be because the code assumes that the set of objects in "N" is unique when doing the eager load, which doesn't hold when "N" is the set of objects in an M-N relationship.

James-REANNZ avatar Oct 19 '23 01:10 James-REANNZ