improve gdb.Model.Fields/FieldsEx for package gdb

This commit is contained in:
John
2020-10-10 14:00:10 +08:00
parent 651aa895f8
commit 09ce105eee

View File

@ -24,18 +24,24 @@ func (m *Model) Filter() *Model {
}
// Fields sets the operation fields of the model, multiple fields joined using char ','.
func (m *Model) Fields(fields string) *Model {
model := m.getModel()
model.fields = fields
return model
func (m *Model) Fields(fields ...string) *Model {
if len(fields) > 0 {
model := m.getModel()
model.fields = gstr.Join(fields, ",")
return model
}
return m
}
// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
// Note that this function supports only single table operations.
func (m *Model) FieldsEx(fields string) *Model {
model := m.getModel()
model.fieldsEx = fields
return model
func (m *Model) FieldsEx(fields ...string) *Model {
if len(fields) > 0 {
model := m.getModel()
model.fieldsEx = gstr.Join(fields, ",")
return model
}
return m
}
// Deprecated, use GetFieldsStr instead.