I have these models
type Message struct {
gorm.Model
UserID uint `json:"userId"`
User userModels.User
Content string `json:"content"`
}
type Receiver struct {
gorm.Model
UserID uint `json:"userId"`
User userModels.User
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Email string `json:"email"`
Address string `json:"address"`
Phone string `json:"phone"`
}
type Delivery struct {
gorm.Model
Message Message `json:"message"`
MessageID uint `json:"messageId"`
Receiver Receiver `json:"Receiver"`
ReceiverID uint `json:"receiverId"`
DeliveryDate time.Time `json:"deliveryDate"`
Sent bool `json:"sent"`
}
I insert some Delivery in the database with certain MessageID and ReceiverID. When I query that certain Delivery I expect to get the regarding message with the id of MessageID, and a Receiver of id ReceiverID. But what I get is a Delivery with both empty Message and Receiver objects.
this is what I get:
{
"ID": 2,
"CreatedAt": "2021-08-26T04:44:33.366628+04:30",
"UpdatedAt": "2021-08-26T04:44:33.366628+04:30",
"DeletedAt": null,
"message": {
"ID": 0,
"CreatedAt": "0001-01-01T00:00:00Z",
"UpdatedAt": "0001-01-01T00:00:00Z",
"DeletedAt": null,
"userId": 0,
"User": {
"ID": 0,
"CreatedAt": "0001-01-01T00:00:00Z",
"UpdatedAt": "0001-01-01T00:00:00Z",
"DeletedAt": null,
"firstName": "",
"lastName": "",
"email": "",
"password": "",
"country": "",
"dateOfBirth": "0001-01-01T00:00:00Z",
"rank": "",
"gender": "",
"plan": ""
},
"content": ""
},
"messageId": 2,
"Receiver": {
"ID": 0,
"CreatedAt": "0001-01-01T00:00:00Z",
"UpdatedAt": "0001-01-01T00:00:00Z",
"DeletedAt": null,
"userId": 0,
"User": {
"ID": 0,
"CreatedAt": "0001-01-01T00:00:00Z",
"UpdatedAt": "0001-01-01T00:00:00Z",
"DeletedAt": null,
"firstName": "",
"lastName": "",
"email": "",
"password": "",
"country": "",
"dateOfBirth": "0001-01-01T00:00:00Z",
"rank": "",
"gender": "",
"plan": ""
},
"firstName": "",
"lastName": "",
"email": "",
"address": "",
"phone": ""
},
"receiverId": 1,
"deliveryDate": "2021-08-25T05:18:27.950457+04:30",
"sent": false
}
While I expect it to return the message with the messageId I specified and also the receiver
