You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you are only selecting a single column and the column is NULL then no object will be returned.
This needs to be documented as expected functionality (assuming it is)
type User struct {
ID int64 // 1
Name string // "Steve"
ProfilePhoto sql.NullString // "NULL"
}
type UserAddress struct {
bun.BaseModel
UserID int64 // 1
User *User `bun:"rel:belongs-to,join:user_id=id"`
Street // "123 Street"
}
address := UserAddress{ID: 1}
err := db.NewSelect().Model(&address).
Relation("User", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column("profile_photo")
}).WherePK().Scan(ctx)
fmt.Println(address.User) // is null because profile_photo was null
err := db.NewSelect().Model(&address).
Relation("User", func(q *bun.SelectQuery) *bun.SelectQuery {
return q.Column("profile_photo", "name")
}).WherePK().Scan(ctx)
fmt.Println(address.User) // is *User because name is not NULL ("Steve")
The text was updated successfully, but these errors were encountered:
If you are only selecting a single column and the column is NULL then no object will be returned.
This needs to be documented as expected functionality (assuming it is)
The text was updated successfully, but these errors were encountered: