分享
多表查询的问题,mysql查询有数据,编写models的时候没传数据(数量是有传值,其他参数没有传值)(models联表查询创建,数据库没有表),各位大神请教下
zhong · · 1499 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
package products
import (
"erp/models"
"github.com/astaxie/beego/orm"
)
type Product_Inventorys struct {
Id int64
Name string
Formate string
Unit string
Warehouse string
C_name string
Purchase string
Price string
Quantity string
}
func init() {
orm.RegisterModel(new(Product_Inventory))
}
//统计仓库存量
func ListInvent()(num int64,err error, invent []Product_Inventorys) {
qb, _ := orm.NewQueryBuilder("mysql")
qb.Select("i.id As Id", "p.name As Name", " p.format As Formate",
"p.unit As Unit","w.w_name As Warehouse","c.name As C_name","p.purchase As Purchase",
"p.sales As Price","i.quantity As Quantity").
From(models.TableName("product_inventory i,pms_product p,pms_product_category c,pms_product_warehouse w") ).
Where("i.product=p.id and i.warehouse=w.w_id and p.c_id=c.id")
sql := qb.String()
o := orm.NewOrm()
var invents []Product_Inventorys
nums, errs := o.Raw(sql).QueryRows(&invents)
return nums,errs,invents
}
[ORM]2019年01月15日 20:08:17 -[Queries/default] - [ OK / db.Query / 233.0ms] - [SELECT i.id As Id, p.name As Name, p.format As Formate, p.unit As Unit, w.w_name As Warehouse, c.name As C_name, p.purchase As Purchase, p.sales As Price, i.quantity As Quantity FROM pms_product_inventory i,pms_product p,pms_product_category c,pms_product_warehouse w WHERE i.product=p.id and i.warehouse=w.w_id and p.c_id=c.id]
[{0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 }]


有疑问加站长微信联系(非本文作者))
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信1499 次点击
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传