pop icon indicating copy to clipboard operation
pop copied to clipboard

EagerPreload only loading last association when using long association paths

Open reggieriser opened this issue 4 years ago • 0 comments

Description

EagerPreload does not seem to be loading all associations in 3+ level association paths where the first 2 levels are the same. Here's an example using the test model structs in pop_test.go:

writers := []Writer{}
tx.EagerPreload("Book.Taxi.Driver", "Book.Taxi.Address").All(&writers)

In this case, only the Book.Taxi.Address struct is populated. The Book.Taxi.Driver struct will have zero values (or be nil if a pointer field).

If I change the above to an Eager call, things seem to work fine.

If I shorten the paths to something smaller like below (but still use EagerPreload), it works fine as well:

writers := []Writer{}
tx.EagerPreload("Book.Taxi", "Book.User").All(&writers)

Steps to Reproduce the Problem

I made a test case that demonstrates the issue in a branch on my fork: https://github.com/gobuffalo/pop/compare/master...reggieriser:preload-third-level-test

Expected Behavior

I would expect identical Eager and EagerPreload calls to be interchangeable with no difference in the resulting structs' values.

Actual Behavior

An association is not being loaded with EagerPreload

Info

Mac OS 10.15.7, Pop 5.3.3, not using Pop through Buffalo

reggieriser avatar Feb 11 '21 20:02 reggieriser