Skip to content

I cant use "join_fk" with "has-one" Relation #1812

@KMACEL

Description

@KMACEL

I want to use "has-one" relation. Example;

type UserDB struct {
	ID int `json:"-" 
	UserID      string    `json:"userID" pg:",unique"`
	 // Other user fields
}

type UserDetailDB struct {
	ID int `json:"-" `
	UserID      string    `json:"userID" pg:",unique"`
	UserDB      *UserDB `json:"user,omitempty" pg:"rel:has-one,fk:user_id,join_fk:user_id"`
      // Other User Detail fields
}

var userDetailDB []UserDetailDB
db.Model(&userDetailDB).Column("user_detail_db.*").Relation("UserDB") ....

When I do this, it creates a query like

LEFT JOIN" user_dbs "AS" user_db "ON" user_db "." Id "=" user_detail_db "." User_id "

While "user_detail_db" gets "user_id" as I want, "user_db" gets "id". I want "user_id" in both tables.

What can I do ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions