diff --git a/models/book.go b/models/book.go index 50579e7..1d265aa 100644 --- a/models/book.go +++ b/models/book.go @@ -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) diff --git a/models/books_list.go b/models/books_list.go index 59611c4..fbf39ce 100644 --- a/models/books_list.go +++ b/models/books_list.go @@ -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) }