Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database Beego:orm Read()与orm RelatedSel()的比较_Database_Go_Orm_Beego - Fatal编程技术网

Database Beego:orm Read()与orm RelatedSel()的比较

Database Beego:orm Read()与orm RelatedSel()的比较,database,go,orm,beego,Database,Go,Orm,Beego,假设我定义了以下结构: type User struct { Id int `orm:"pk;auto" Username string `orm:"size(64);unique"` Email string `orm:"size(255);unique"` Password string `orm:"size(64)"` Profile *Profile `orm:"rel(one);on_delete(cascade)"` } type

假设我定义了以下结构:

type User struct {
Id       int       `orm:"pk;auto"
Username string    `orm:"size(64);unique"`
Email    string    `orm:"size(255);unique"`
Password string    `orm:"size(64)"`
Profile  *Profile  `orm:"rel(one);on_delete(cascade)"`
}

type Profile struct {
Id          int    `orm:"pk;auto"`
User        *User  `orm:"reverse(one)"`
Description string `orm:"size(255)"`
}
如果我只需要第一个结构中的信息(User.Id、User.Password、User.Email或User.Username),而直接执行级联查询,那么我的应用程序在性能方面会受到多大影响

基本上做:

o := orm.NewOrm()

user := &User{}
err := o.QueryTable("user").Filter("Username", username).RelatedSel().One(user)
而不是

o := orm.NewOrm()

user := &User{Username: username}
err := o.Read(user, "username")