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

Failing test for netip.Addr #786

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

and3rson
Copy link

@and3rson and3rson commented Jan 25, 2025

Explain your user case and expected results

Expected netip.Addr to work as per pgx docs:

diff --git a/models.go b/models.go
index 692a684..3dd89cf 100644
--- a/models.go
+++ b/models.go
@@ -2,6 +2,7 @@ package main
 
 import (
 	"database/sql"
+	"net/netip"
 	"time"
 
 	"gorm.io/gorm"
@@ -27,6 +28,7 @@ type User struct {
 	Languages []Language `gorm:"many2many:UserSpeak"`
 	Friends   []*User    `gorm:"many2many:user_friends"`
 	Active    bool
+	NetAddr   netip.Addr `gorm:"type:inet"`
 }

Actual result is:

[error] invalid field found for struct gorm.io/playground.User's field NetAddr: define a valid foreign key for relations or implement the Valuer/Scanner interface
2025/01/25 15:50:03
[error] failed to parse value &main.User{Model:gorm.Model{ID:0x0, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletedAt:gorm.DeletedAt{Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Valid:false}}, Name:"", Age:0x0, Birthday:<nil>, Account:main.Account{Model:gorm.Model{ID:0x0, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletedAt:gorm.DeletedAt{Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Valid:false}}, UserID:sql.NullInt64{Int64:0, Valid:false}, Number:""}, Pets:[]*main.Pet(nil), Toys:[]main.Toy(nil), CompanyID:(*int)(nil), Company:main.Company{ID:0, Name:""}, ManagerID:(*uint)(nil), Manager:(*main.User)(nil), Team:[]main.User(nil), Languages:[]main.Language(nil), Friends:[]*main.User(nil), Active:false, NetAddr:netip.Addr{addr:netip.uint128{hi:0x0, lo:0x0}, z:unique.Handle[net/netip.addrDetail]{value:(*netip.addrDetail)(nil)}}}, got error invalid field found for struct gorm.io/playground.User's field NetAddr: define a valid foreign key for relations or implement the Valuer/Scanner interface

@and3rson
Copy link
Author

Closing as per go-gorm/gorm#7359 (comment).

@and3rson and3rson closed this Jan 25, 2025
@and3rson
Copy link
Author

Reopening since the issue persists.

@and3rson and3rson reopened this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant