我在jinzhu GORM包中用于连接数据库等
这是我的代码
package pizzas
import (
"github.com/jinzhu/gorm"
"github.com/gin-gonic/gin"
"speedy-gonzales/db"
"net/http"
)
type Pizza struct {
gorm.Model
Name string `gorm:"not null"`
Image string `sql:"type:text"`
PSizesAndPrices []PizzaPriceSize
}
type PizzaPriceSize struct {
gorm.Model
SizeTitle string `gorm:"column:size_title;type:varchar(50);not null'"`
PriceEur int `gorm:"column:price_eur"`
PriceBam int `gorm:"column:price_bam"`
PizzaID uint `gorm:"index"`
}
func (PizzaPriceSize) TableName() string {
return "pizza_price_sizes"
}
func FetchPizzasWithSizes(c *gin.Context) {
var pizza_model []Pizza
var p_sizes_prices_model []PizzaPriceSize
dB := db.DbConnect()
dB.Debug().Model(&pizza_model).Related(&p_sizes_prices_model)
c.JSON(http.StatusOK, gin.H{
"status": http.StatusOK,
"message": p_sizes_prices_model,
})
return
}
当我运行应用程序时,这是我从调试控制台获得的:
SELECT * FROM pizza_price_sizes
WHERE pizza_price_sizes
。deleted_at
IS NULL AND((pizza_id
=' 0'))
我的问题是如何将pizza_id传递给此查询?