Skip to content

Commit

Permalink
chore: join queries still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
1995parham committed Sep 22, 2024
1 parent bf46366 commit 8d9928d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/store/student/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (sql SQL) Get(id string) (model.Student, error) {

if err := sql.DB.Model(new(SQLItem)).
Joins("LEFT JOIN `students_courses` ON `students`.`id` = `students_courses`.`sql_item_id`").
Joins("LEFT JOIN `courses` ON `courses`.`id` = `students_courses`.`course_id`").
Joins("LEFT JOIN (select `id` `Courses_id`, `name` `Courses_name` from `courses`) ON `Courses_id` = `students_courses`.`course_id`").
Take(&st, id).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return model.Student{}, ErrStudentNotFound
Expand All @@ -113,6 +113,8 @@ func (sql SQL) Get(id string) (model.Student, error) {
return model.Student{}, err
}

log.Println(st)

courses := make([]model.Course, 0, len(st.Courses))
for _, course := range st.Courses {
courses = append(courses, model.Course{
Expand Down

0 comments on commit 8d9928d

Please sign in to comment.