Closed focusonline closed 5 years ago
I added some code to skip processing hidden properties and error disappeared, but it can not find common fields as well, always tells me no primiary key...
Find query multiple records from database, also you can use join and extends
type User struct {
Id int64
Name string
Salt string
Age int
Passwd string `xorm:"varchar(200)"`
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
var users []User
err := engine.Where("name = ?", name).And("age > 10").Limit(10, 0).Find(&users)
// SELECT * FROM user WHERE name = ? AND age > 10 limit 10 offset 0
type Detail struct {
Id int64
UserId int64 `xorm:"index"`
}
type UserDetail struct {
User `xorm:"extends"`
Detail `xorm:"extends"`
}
var users []UserDetail
err := engine.Table("user").Select("user.*, detail.*").
Join("INNER", "detail", "detail.user_id = user.id").
Where("user.name = ?", name).Limit(10, 0).
Find(&users)
// SELECT user.*, detail.* FROM user INNER JOIN detail WHERE user.name = ? limit 10 offset 0
but Detail and User is real table in your case, I just defined some common fields not a real table as struct so I do not think it can resolve my problem. thank you for your help.
for example,
there are some common fields for many tables like id or createtime and so forth. but common fields in a hidden struct because it can not be used by others. when using B to query, the func mapType will raise error at engine.go:1031 `if , ok := fieldValue.Addr().Interface().(core.Conversion); ok {` will this be fixed to support inheritance for common fields?