| | |
| | | Orm *gorm.DB |
| | | CategoryIds []int |
| | | Preload bool |
| | | Fields string |
| | | } |
| | | |
| | | IdAndName struct { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MaterialSearch) SetFields(fields string) *MaterialSearch { |
| | | slf.Fields = fields |
| | | return slf |
| | | } |
| | | |
| | | func (slf *MaterialSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | |
| | | } |
| | | if len(slf.CategoryIds) > 0 { |
| | | db = db.Where("category_id in ?", slf.CategoryIds) |
| | | } |
| | | |
| | | if slf.Fields != "" { |
| | | db = db.Select(slf.Fields) |
| | | } |
| | | |
| | | if slf.Preload { |
| | |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func MaterialMap(records []*Material) (m map[string]*Material) { |
| | | m = make(map[string]*Material, len(records)) |
| | | for _, record := range records { |
| | | m[record.ID] = record |
| | | } |
| | | return m |
| | | } |