Fields appends `fieldNamesOrMapStruct` to the operation fields of the model, multiple fields joined using char ','. The parameter `fieldNamesOrMapStruct` can be type of string/map/*map/struct/*struct. Example: Fields("id", "name", "age") Fields([]string{"id", "name", "age"}) Fields(map[string]any{"
(fieldNamesOrMapStruct ...any)
| 24 | // Fields(map[string]any{"id":1, "name":"john", "age":18}) |
| 25 | // Fields(User{Id: 1, Name: "john", Age: 18}). |
| 26 | func (m *Model) Fields(fieldNamesOrMapStruct ...any) *Model { |
| 27 | length := len(fieldNamesOrMapStruct) |
| 28 | if length == 0 { |
| 29 | return m |
| 30 | } |
| 31 | fields := m.filterFieldsFrom(m.tablesInit, fieldNamesOrMapStruct...) |
| 32 | if len(fields) == 0 { |
| 33 | return m |
| 34 | } |
| 35 | model := m.getModel() |
| 36 | return model.appendToFields(fields...) |
| 37 | } |
| 38 | |
| 39 | // FieldsPrefix performs as function Fields but add extra prefix for each field. |
| 40 | func (m *Model) FieldsPrefix(prefixOrAlias string, fieldNamesOrMapStruct ...any) *Model { |