I'm absolutely stuck at Beego, update & get. I already done getall, delete,
Problem is my ID is the primary key. I convert into a string to equal at the model. How to search from Ticket table by using ID and in model how to take as []array and return it.
controller
func (i *TicketController) GetTicket() {
ID := i.GetInt("ID")
stringID := strconv.Itoa(ID)
if ID != "" {
ticket := models.GetTicketById(stringID)
fmt.Println(ticket)
i.Data["json"] = ticket
}
i.ServeJSON()
}
model
func GetTicketById(id int64) Ticket {
t := Ticket{ID: id}
o := orm.NewOrm()
err := o.Read(&t)
if err == orm.ErrNoRows {
fmt.Println("no result")
} else if err == orm.ErrMissPK {
fmt.Println("can't find PK")
}
return t
}
I think you are misunderstand many things. I fixed your code on this link.