CustomData returns a shallow copy ONLY of the custom record fields data, aka. fields that are neither defined by the collection, nor special system ones. Note that custom fields prefixed with "@pbInternal" are always skipped.
()
| 788 | // |
| 789 | // Note that custom fields prefixed with "@pbInternal" are always skipped. |
| 790 | func (m *Record) CustomData() map[string]any { |
| 791 | if m.data == nil { |
| 792 | return nil |
| 793 | } |
| 794 | |
| 795 | fields := m.Collection().Fields |
| 796 | |
| 797 | knownFields := make(map[string]struct{}, len(fields)) |
| 798 | |
| 799 | for _, f := range fields { |
| 800 | knownFields[f.GetName()] = struct{}{} |
| 801 | } |
| 802 | |
| 803 | result := map[string]any{} |
| 804 | |
| 805 | rawData := m.data.GetAll() |
| 806 | for k, v := range rawData { |
| 807 | if _, ok := knownFields[k]; !ok { |
| 808 | // skip internal custom fields |
| 809 | if strings.HasPrefix(k, internalCustomFieldKeyPrefix) { |
| 810 | continue |
| 811 | } |
| 812 | |
| 813 | result[k] = v |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | return result |
| 818 | } |
| 819 | |
| 820 | // WithCustomData toggles the export/serialization of custom data fields |
| 821 | // (false by default). |