Open aditya37 opened 4 years ago
You can do like this..
var employeAccounts []EmployeAccount
var educations []EmployeEducation
// write mysql's inner join query and bind data in employeAccounts
for _ , item := range employeAccounts {
educations = append(educations, item.EmployeEducation)
}
employeAccounts[0].EmployeEducations = educations
hay sir. i have struct like this
type EmployeAccount struct { Id int64
json:"idEmploye"Username string
json:"username"Password string
json:"password"Email string
json:"email"PhotoProfile string
db:"photo_profile" json:"photo_profile"RefreshToken string
db:"refresh_token" json:"refresh_token"IsActive string
db:"is_active" json:"isActive"DateCreate time.Time
db:"date_create" json:"date_create"DateUpdate time.Time
db:"date_update" json:"date_update"EmployeEducations []EmployeEducation
json:"employe_education"}
type EmployeEducation struct { InstitutionName string
db:"institution_name" json:"institution_name"Degree string
db:"degree" json:"degree"Certificate string
db:"certificate" json:"certificate_link"IsActive string
db:"is_active" json:"IsActive"StartEducation time.Time
db:"start_education" json:"start_education"EndEducation time.Time
db:"end_education" json:"end_education"EmployeId int64
db:"employe_id" json:"-"}
and i want create result with inner join like this{ "status": 1, "message": "Success Load data", "Result": [{ "idEmploye": 1602606154, "username": "aditrah_09", "password": "$2a$10$h/L3M0SbkDqPx8kh9LkNEOZZ93s6L5NelmqAdf8NeLhGOb01.h7Ri", "email": "aditrahman909@gmail.com", "photo_profile": "https://storage.googleapis.com/download/storage/v1/b/backend-jobs-go.appspot.com/o/employe-photo-aditrah_09?generation=1602606154351311&alt=media", "refresh_token": "LpGNiDHyOrVUEgkgnyUm", "isActive": "", "date_create": "2020-10-13T23:22:34.587073+07:00", "date_update": "2020-10-13T23:22:34.587073+07:00", "employe_education": [{ "institution_name": "Polinema", "degree": "D2", "certificate_link": "http://google.com ", "IsActive": "True ", "start_education": "2020-10-26T00:00:00Z", "end_education": "2020-10-26T00:00:00Z" }, { "institution_name": "SMKN 3 Bojonegoro", "degree": "SMK", "certificate_link": "http://google.com ", "IsActive": "True ", "start_education": "2020-10-26T00:00:00Z", "end_education": "2020-10-26T00:00:00Z" }] }] }
and how to solve this case