I have several structures, one of which contains all the rest. I need to use GORM to get the main structure.
I tried to use gorm tag with 'column', but doesn't work
package database
import (
"database/sql"
"time"
)
type TaskItem struct {
Ind int32 `gorm:"column:Ind"`
ParentIndArray sql.NullString `gorm:"column:ParentIndArray"`
ParentInd int32 `gorm:"column:ParentInd"`
SourceId string `gorm:"column:SourceId"`
SourceInd int32 `gorm:"column:SourceInd"`
ContentIndActive int32 `gorm:"column:ContentIndActive"`
StatusIndInit int32 `gorm:"column:StatusIndInit"`
StatusIndActive int32 `gorm:"column:StatusIndActive"`
TaskTypeInd int32 `gorm:"column:TaskTypeInd"`
RootTaskTypeInd int32 `gorm:"column:RootTaskTypeInd"`
FieldInd int32 `gorm:"column:FieldInd"`
StateIndActive int32 `gorm:"column:StateIndActive"`
ChildIndArray []byte `gorm:"column:ChildIndArray"`
}
type TaskContent struct {
Ind int32 `gorm:"column:ContentInd"`
TaskInd int32 `gorm:"-"`
SessionInd int32 `gorm:"column:ContentSessInd"`
Caption string `gorm:"column:Caption"`
Content []byte `gorm:"column:Content"`
Priority int32 `gorm:"column:Priority"`
PlanningDateStart time.Time `gorm:"column:PlanningDateStart"`
PlanningDateEnd time.Time `gorm:"column:PlanningDateEnd"`
TimeEstimate time.Time `gorm:"column:TimeEstimate"`
ApplyDate time.Time `gorm:"column:ContentApplyDate"`
}
type TaskStatus struct {
Ind int32 `gorm:"column:StatusInd"`
TaskInd int32 `gorm:"-"`
ChainId string `gorm:"column:ChainId"`
MessageId string `gorm:"column:MessageID"`
SessionInd int32 `gorm:"column:StatusSessInd"`
StatusInd int32 `gorm:"column:Status"`
Text string `gorm:"column:Text"`
Comment string `gorm:"column:Comment"`
ApplyDate time.Time `gorm:"column:StatusApplyDate"`
ReceiveData time.Time `gorm:"column:StatusReceiveDate"`
}
type TaskState struct {
Ind int32 `gorm:"column:StateInd"`
TaskInd int32 `gorm:"-"`
SessionInd int32 `gorm:"column:StateSessInd"`
State int32 `gorm:"column:State"`
ApplyDate time.Time `gorm:"column:StateApplyDate"`
}
type Task struct {
Item TaskItem
Content TaskContent
Status TaskStatus
State TaskState
}
I expect Task to contain other data from database. What should I do?
Note. At first, I use:
// tasks is equal []Task
err = database.db.Raw("CALL pr_task_list_by_account_ind(?)", accountGroupInd).Scan(&tasks)
Then I decided to try using:
var ti []TaskItem
var tc []TaskContent
var tse []TaskState
var tss []TaskStatus
err = database.db.Raw("CALL pr_task_list_by_account_ind(?)", accountGroupInd).Scan(&ti).Scan(&tc).Scan(&tse).Scan(&tss).Error
and I noticed that the first scanner works, and if I remove it, then the second scanner starts to work too