Declaring the Instructor and Course models

Report a typo

Edwin wants to create a new in-memory SQLite database that contains the instructors and courses tables and set up a one-to-many relationship between them.

The instructors table should have the following columns:

instructors
id INTEGER, PK
created_at DATETIME
updated_at DATETIME
deleted_at DATETIME
first_name TEXT
last_name TEXT
email TEXT

And the courses table should have the following columns:

courses
id INTEGER, PK
created_at DATETIME
updated_at DATETIME
deleted_at DATETIME
code INTEGER
title TEXT
instructor_id INTEGER FK(instructors)

Your task is to help Edwin write the required code to declare the Instructor and Course models, using the gorm.Model struct, and setting up a one-to-many relationship between them.

This problem uses the reflect package and the hidden function checkModels() to check if you correctly declared the Instructor and Course models and set up a one-to-many relationship between them.
Write a program in Go
package main

import (
"fmt"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"log"
"reflect"
"strings"
"unicode"
)

// Declare the `Instructor` model below:
type Instructor struct {
gorm.Model
? ?
? ?
? ?
? []Course
}

// Declare the `Course` model below:
type Course struct {
?
? ?
? ?
InstructorID ?
}

// DO NOT delete or modify the code within the main() function!
func main() {
_ = fmt.Print; _ = log.Print; _ = gorm.Config{}; _ = sqlite.Dialector{}
_ = reflect.Struct; _ = strings.ToLower;_ = unicode.IsUpper

checkModels()
}

Create a free account to access the full topic