change table to references
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package models
|
||||
|
||||
type Event struct {
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Date string `gorm:"column:date" json:"date"`
|
||||
Attendees Persons `gorm:"type:json" json:"attendees"`
|
||||
Count int `gorm:"column:count" json:"count"`
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
Date string `gorm:"column:date" json:"date"`
|
||||
Day string `gorm:"column:day" json:"day"`
|
||||
Attendees []*Member `gorm:"many2many:member_events;"`
|
||||
}
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
package models
|
||||
|
||||
type Member struct {
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
FirstName string `gorm:"column:firstName" json:"firstName,omitempty"`
|
||||
FirstNameHash string `gorm:"column:firstNameHash" json:"-"`
|
||||
LastName string `gorm:"column:lastName" json:"lastName,omitempty"`
|
||||
LastNameHash string `gorm:"column:lastNameHash" json:"-"`
|
||||
Birthday string `gorm:"column:birthday" json:"birthday,omitempty"`
|
||||
BirthdayHash string `gorm:"column:birthdayHash" json:"-"`
|
||||
Address string `gorm:"column:address" json:"address,omitempty"`
|
||||
Zip string `gorm:"column:zip" json:"zip,omitempty"`
|
||||
Town string `gorm:"column:town" json:"town,omitempty"`
|
||||
Phone string `gorm:"column:phone" json:"phone,omitempty"`
|
||||
Email string `gorm:"column:email" json:"email,omitempty"`
|
||||
FirstVisit string `gorm:"column:firstVisit" json:"firstVisit,omitempty"`
|
||||
LastVisit string `gorm:"column:lastVisit" json:"lastVisit,omitempty"`
|
||||
Group string `gorm:"column:group" json:"group,omitempty"`
|
||||
ResponsiblePerson Person `gorm:"type:json" json:"responsiblePerson"`
|
||||
Comment string `gorm:"column:comment" json:"comment"`
|
||||
Id int `gorm:"primaryKey" json:"id,omitempty"`
|
||||
FirstName string `gorm:"column:firstName" json:"firstName,omitempty"`
|
||||
FirstNameHash string `gorm:"column:firstNameHash" json:"-"`
|
||||
LastName string `gorm:"column:lastName" json:"lastName,omitempty"`
|
||||
LastNameHash string `gorm:"column:lastNameHash" json:"-"`
|
||||
Birthday string `gorm:"column:birthday" json:"birthday,omitempty"`
|
||||
BirthdayHash string `gorm:"column:birthdayHash" json:"-"`
|
||||
Address string `gorm:"column:address" json:"address,omitempty"`
|
||||
Zip string `gorm:"column:zip" json:"zip,omitempty"`
|
||||
Town string `gorm:"column:town" json:"town,omitempty"`
|
||||
Phone string `gorm:"column:phone" json:"phone,omitempty"`
|
||||
Email string `gorm:"column:email" json:"email,omitempty"`
|
||||
FirstVisit string `gorm:"column:firstVisit" json:"firstVisit,omitempty"`
|
||||
LastVisit string `gorm:"column:lastVisit" json:"lastVisit,omitempty"`
|
||||
GroupId *int `json:"GroupId,omitempty"`
|
||||
Group *Group `gorm:"foreignKey:GroupId" json:"group,omitempty"`
|
||||
ResponsibleId *int `json:"ResponsibleId,omitempty"`
|
||||
Responsible *Member `gorm:"foreignKey:ResponsibleId" json:"responsible,omitempty"`
|
||||
Comment string `gorm:"column:comment" json:"comment,omitempty"`
|
||||
Events []*Event `gorm:"many2many:member_events;" `
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Persons []Person
|
||||
|
||||
// --- Implement driver.Valuer (for saving to DB)
|
||||
func (r Persons) Value() (driver.Value, error) {
|
||||
return json.Marshal(r)
|
||||
}
|
||||
|
||||
// --- Implement sql.Scanner (for reading from DB)
|
||||
func (r *Persons) Scan(value any) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to unmarshal Settings: %v", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, r)
|
||||
}
|
||||
|
||||
type Person struct {
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
FirstName string `gorm:"column:firstName" json:"firstName"`
|
||||
LastName string `gorm:"column:lastName" json:"lastName"`
|
||||
}
|
||||
|
||||
// --- Implement driver.Valuer (for saving to DB)
|
||||
func (r Person) Value() (driver.Value, error) {
|
||||
return json.Marshal(r)
|
||||
}
|
||||
|
||||
// --- Implement sql.Scanner (for reading from DB)
|
||||
func (r *Person) Scan(value any) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("failed to unmarshal Settings: %v", value)
|
||||
}
|
||||
return json.Unmarshal(bytes, r)
|
||||
}
|
||||
Reference in New Issue
Block a user