package orm

import (
	"errors"

	"github.com/jinzhu/gorm"
)

type Subject struct {
	gorm.Model
	Name         string
	DepartmentId uint
	Teachers     []Teacher `gorm:"many2many:teacher_subjects;"`
}

func (s *Subject) Create(db *gorm.DB, record map[string]interface{}) error {
	result := new(Subject)
	if name := record["name"]; name == nil {
		return errors.New("Error in updating subject: field name is empty")
	} else {
		result.Name = name.(string)
	}
	db.Create(result)
	return nil
}
