1 Star 1 Fork 0

bigbase / pg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
model_many.go 925 Bytes
一键复制 编辑 原始数据 按行查看 历史
package orm
import (
"fmt"
"reflect"
)
type manyModel struct {
*sliceTableModel
rel *Relation
buf []byte
dstValues map[string][]reflect.Value
}
var _ tableModel = (*manyModel)(nil)
func newManyModel(j *join) *manyModel {
joinModel := j.JoinModel.(*sliceTableModel)
dstValues := dstValues(joinModel.Root(), joinModel.Path(), j.BaseModel.Table().PKs)
return &manyModel{
sliceTableModel: joinModel,
rel: j.Rel,
dstValues: dstValues,
}
}
func (m *manyModel) NewModel() ColumnScanner {
m.strct = reflect.New(m.table.Type).Elem()
m.structTableModel.NewModel()
return m
}
func (m *manyModel) AddModel(_ ColumnScanner) error {
m.buf = modelId(m.buf[:0], m.strct, m.rel.FKs)
dstValues, ok := m.dstValues[string(m.buf)]
if !ok {
return fmt.Errorf("pg: can't find dst value for model id=%q", m.buf)
}
for _, v := range dstValues {
v.Set(reflect.Append(v, m.strct))
}
return nil
}
Go
1
https://gitee.com/bigbase/pg.git
git@gitee.com:bigbase/pg.git
bigbase
pg
pg
v4.6.0

搜索帮助