Added lookup one single book

Signed-off-by: kolaente <konrad@kola-entertainments.de>
This commit is contained in:
konrad 2017-10-10 17:14:51 +02:00 committed by kolaente
parent 167ba086d7
commit fed91b9e8a
2 changed files with 9 additions and 2 deletions

View File

@ -22,9 +22,9 @@ func (Book) TableName() string{
}
func GetBookById(ID string) (book Book, err error) {
// Get the Book
_, err = x.ID(ID).Get(&book)
// Get publisher
publisher := Publisher{ID: book.Publisher}
_, err = x.Get(&publisher)

View File

@ -2,9 +2,16 @@ package models
import "fmt"
type BookPublisher struct {
Book `xorm:"extends"`
Publisher `xorm:"extends"`
}
func ListBooks() (books []*Book, err error) {
err = x.Find(&books)
err = x.Table("books").
//Join("INNER", "publishers", "books.publisher = publishers.id").
Find(&books)
if err != nil {
fmt.Println("Error getting Books", err)
}