I am developing the Go code where I am making the tables join using GORM, following the structs I have defined for that:
type MpUserFriend struct{
gorm.Model
FriendKey string
SenderId uint
RecieverId uint `gorm:"index"`
Reciever MpUser `gorm:"ForeignKey:RecieverId"`
Status string
}
type MpUser struct{
gorm.Model
FirstName string
MiddleName string
LastName string
Email string `validate:"required,email"`
UserName string `validate:"required"`
UserType string
Status int
}
And following the way I am getting the data from the database:
friend := DbModel.MpUserFriend{}
friends := []DbModel.MpUserFriend{}
DB.Debug().Where("(sender_id = ? and reciever_id != ?) or (sender_id != ? and reciever_id=?)",strconv.Itoa(int(userAuth.UserDetail.ID)),strconv.Itoa(int(userAuth.UserDetail.ID)),strconv.Itoa(int(userAuth.UserDetail.ID)),strconv.Itoa(int(userAuth.UserDetail.ID)) ).Find(&friend)
DB.Debug().Model(&friend).Related(&friend.Reciever,"reciever_id").Find(&friends)
and following the output, I am getting from the above code:
[0] => stdClass Object
(
[ID] => 3
[CreatedAt] => 2019-01-09T01:31:49-08:00
[UpdatedAt] => 2019-01-09T01:31:49-08:00
[DeletedAt] =>
[FriendKey] => jFF4tzj5ZG9Vh3l8X6ek6s-JdTWz0_QcrKVYfWrzqgk=
[SenderId] => 7
[RecieverId] => 1
[Reciever] => stdClass Object
(
[ID] => 0
[CreatedAt] => 0001-01-01T00:00:00Z
[UpdatedAt] => 0001-01-01T00:00:00Z
[DeletedAt] =>
[FirstName] =>
[MiddleName] =>
[LastName] =>
[Email] =>
[UserName] =>
[Status] => 0
)
[Status] => 0
)
Actually, I am not receiving the related user's detail, please help where I am making the mistake