mirror of
https://github.com/go-home-admin/toolset.git
synced 2025-12-24 13:37:52 +08:00
update: 多层关联查询时支持蛇型写法,如:Preload("user.user_role")
This commit is contained in:
@@ -267,7 +267,11 @@ func (orm *OrmMysqlTableName) Or(fuc func(orm *OrmMysqlTableName)) *OrmMysqlTabl
|
||||
// Preload preload associations with given conditions
|
||||
// db.Preload("Orders|orders", "state NOT IN (?)", "cancelled").Find(&users)
|
||||
func (orm *OrmMysqlTableName) Preload(query string, args ...interface{}) *OrmMysqlTableName {
|
||||
orm.db.Preload(home.StringToHump(query), args...)
|
||||
arr := strings.split(query, ".")
|
||||
for i, _ := range arr {
|
||||
arr[i] = home.StringToHump(arr[i])
|
||||
}
|
||||
orm.db.Preload(strings.Join(arr, "."), args...)
|
||||
return orm
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user