Clone returns a shallow copy of the current record model with all of its collection and unknown fields data, expand and flags copied.
use [Record.Fresh()] instead if you want a copy with only the latest collection fields data and everything else reset to the defaults.
Collection returns the Collection model associated with the current Record model.
NB! The returned collection is only for read purposes and it shouldn't be modified because it could have unintended side-effects on other Record models from the same collection.
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.
DBExport implements the [DBExporter] interface and returns a key-value map with the data to be persisted when saving the Record in the database.
Expand returns a shallow copy of the current Record model expand data (if any).
ExpandedAll retrieves a slice of relation Records from the already loaded expand data of the current model.
If the requested expand relation is single, this method normalizes the return result and will wrap the single model as a slice.
Returns nil slice if there is no such expand relation loaded.
ExpandedOne retrieves a single relation Record from the already loaded expand data of the current model.
If the requested expand relation is multiple, this method returns only first available Record from the expanded relation.
Returns nil if there is no such expand relation loaded.
FieldsData returns a shallow copy ONLY of the collection's fields record's data.
GetUploadedFiles returns the uploaded files for the provided "file" field key, (aka. the current [*filesytem.File] values) so that you can apply further validations or modifications (including changing the file name or content before persisting).
Example:
files := record.GetUploadedFiles("documents")
for _, f := range files {
f.Name = "doc_" + f.Name // add a prefix to each file name
}
app.Save(record) // the files are pointers so the applied changes will transparently reflect on the record value
HasExpired checks if the mfa is expired, aka. whether it has been more than maxElapsed time since its creation.
IgnoreUnchangedFields toggles the flag to ignore the unchanged fields from the DB export for the UPDATE SQL query.
This could be used if you want to save only the record fields that you've changed without overwrite other untouched fields in case of concurrent update.
Load bulk loads the provided data into the current Record model.
MergeExpand merges recursively the provided expand data into the current model's expand (if any).
Note that if an expanded prop with the same key is a slice (old or new expand) then both old and new records will be merged into a new slice (aka. a :merge: [b,c] => [a,b,c]). Otherwise the "old" expanded record will be replace with the "new" one (aka. a :merge: aNew => aNew).
NewStaticAuthToken generates and returns a new static record authentication token.
Static auth tokens are similar to the regular auth tokens, but are non-refreshable and support custom duration.
Zero or negative duration will fallback to the duration from the auth collection settings.
Original returns a shallow copy of the current record model populated with its ORIGINAL db data state (aka. right after PostScan()) and everything else reset to the defaults.
If record was created using NewRecord() the original will be always a blank record (until PostScan() is invoked).
PostScan implements the [dbx.PostScanner] interface.
It essentially refreshes/updates the current Record original state as if the model was fetched from the databases for the first time.
Or in other words, it means that m.Original().FieldsData() will have the same values as m.Record().FieldsData().
PublicExport exports only the record fields that are safe to be public.
To export unknown data fields you need to set record.WithCustomData(true).
For auth records, to force the export of the email field you need to set record.IgnoreEmailVisibility(true).
ReplaceModifiers returns a new map with applied modifier values based on the current record and the specified data.
The resolved modifier keys will be removed.
Multiple modifiers will be applied one after another, while reusing the previous base key value result (ex. 1; -5; +2 => -2).
Note that because Go doesn't guaranteed the iteration order of maps, we would explicitly apply shorter keys first for a more consistent and reproducible behavior.
Example usage:
newData := record.ReplaceModifiers(data)
// record: {"field": 10}
// data: {"field+": 5}
// result: {"field": 15}
SetExpand replaces the current Record's expand with the provided expand arg data (shallow copied).
SetIfFieldExists sets the provided key-value data pair into the current Record model ONLY if key is existing Collection field name/modifier.
This method does nothing if key is not a known Collection field name/modifier.
On success returns the matched Field, otherwise - nil.
To set any key-value, including custom/unknown fields, use the [Record.Set] method.
Id is the primary key of the model. It is usually autogenerated by the parent model implementation.
Generated using TypeDoc
MFA defines a Record proxy for working with the mfas collection.