volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

Incorrect eager loading on non singular relation #1266

Open vincekieft opened 1 year ago

vincekieft commented 1 year ago

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 commented 1 year ago

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

stephenafamo commented 1 year ago

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.

vincekieft commented 1 year ago

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

James-REANNZ commented 10 months ago

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.