Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

belongs_to preload issue #553

Open
rjgonzale opened this issue May 23, 2020 · 0 comments
Open

belongs_to preload issue #553

rjgonzale opened this issue May 23, 2020 · 0 comments
Labels
f: associations the associations feature in pop s: triage Some tests need to be run to confirm the issue

Comments

@rjgonzale
Copy link

rjgonzale commented May 23, 2020

Description

Add primary_id tag to belongs_to association when using EagerPreload

1 -
Right now if you are not using preload you can define the primary key field name when using belongs_to

But, if you use preload, it is hardcoded to be id

The code to change this can be (please excuse me that I am not to buffalo)

diff --git a/preload_associations.go b/preload_associations.go
index 5d3be99..7fa2b68 100644
--- a/preload_associations.go
+++ b/preload_associations.go
@@ -358,7 +358,10 @@ func preloadBelongsTo(tx *Connection, asoc *AssociationMetaInfo, mmi *ModelMetaI
        }

        // 2) load all associations constraint by association fields ids.
-       fk := "id"
+       fk := asoc.Field.Tag.Get("primary_id")
+        if fk == "" {
+                fk = "id"
+        }
@sio4 sio4 added s: triage Some tests need to be run to confirm the issue f: associations the associations feature in pop labels Sep 20, 2022
@sio4 sio4 added this to the v6.1.0 milestone Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: associations the associations feature in pop s: triage Some tests need to be run to confirm the issue
Projects
None yet
Development

No branches or pull requests

2 participants