EagerPreload failing to load association #603
Labels
f: associations
the associations feature in pop
s: triage
Some tests need to be run to confirm the issue
Milestone
Description
I ran into a case where
EagerPreload
fails to pull in an association that works fine withEager
.Here's an example set of models that will demonstrate the problem (the referenced Address model is from
pop_test.go
):And here's an example query using those models:
The
NewAddress
field will fail to be populated usingEagerPreload
, but populates fine withEager
. Tracing through the preload code, it appears to be trying to find the foreign key namedaddress_id
for theNewAddress
association despite the fact it should probably first look fornew_address_id
. It then appears to then be walking down into theEmployee
struct and matching theaddress_id
field, leading to the issue.Note that if I add a
fk_id:"new_address_id"
struct tag toNewAddress
, it works fine. But that's not required forEager
, and I would expect Pop to default thefk_id
tonew_address_id
given the name of the struct field.Steps to Reproduce the Problem
I made a test case that demonstrates the issue in a branch on my fork: master...reggieriser:preload-nested-test
Expected Behavior
I would expect identical
Eager
andEagerPreload
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.1, not using Pop through Buffalo
The text was updated successfully, but these errors were encountered: