FindFileFieldByFile returns the first file type field for which any of the record's data contains the provided filename.
(filename string)
| 1074 | // FindFileFieldByFile returns the first file type field for which |
| 1075 | // any of the record's data contains the provided filename. |
| 1076 | func (m *Record) FindFileFieldByFile(filename string) *FileField { |
| 1077 | for _, field := range m.Collection().Fields { |
| 1078 | if field.Type() != FieldTypeFile { |
| 1079 | continue |
| 1080 | } |
| 1081 | |
| 1082 | f, ok := field.(*FileField) |
| 1083 | if !ok { |
| 1084 | continue |
| 1085 | } |
| 1086 | |
| 1087 | filenames := m.GetStringSlice(f.GetName()) |
| 1088 | if slices.Contains(filenames, filename) { |
| 1089 | return f |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | return nil |
| 1094 | } |
| 1095 | |
| 1096 | // DBExport implements the [DBExporter] interface and returns a key-value |
| 1097 | // map with the data to be persisted when saving the Record in the database. |