static/jsvm/classes/Collection.html
Collection model class.
const collection = new Collection({ type: "base", name: "article", listRule: "@request.auth.id != '' || status = 'public'", viewRule: "@request.auth.id != '' || status = 'public'", deleteRule: "@request.auth.id != ''", fields: [{ name: "title", type: "text", required: true, min: 6, max: 100, }, { name: "description", type: "text", },]})Copy
addIndexbaseFilesPathdbExportgetIndexintegrityChecksisAuthisBaseisNewisViewlastSavedPKmarkAsNewmarkAsNotNewmarshalJSONpkpostScanremoveIndexstringtableNameunmarshalJSON
authAlertauthRule?authTokenconfirmEmailChangeTemplatecreateRule?createddeleteRule?emailChangeTokenfieldsfileTokenidindexeslistRule?manageRule?mfanameoauth2otppasswordAuthpasswordResetTokenrawOptionsresetPasswordTemplatesystemtypeupdateRule?updatedverificationTemplateverificationTokenviewQueryviewRule?
Optional data: Partial<Collection>AddIndex adds a new index into the current collection.
If the collection has an existing index matching the new name it will be replaced with the new one.
BaseFilesPath returns the storage dir path used by the collection.
DBExport prepares and exports the current collection data for db persistence.
GetIndex returns s single Collection index expression by its name.
IntegrityChecks toggles the current collection integrity checks (ex. checking references on delete).
IsAuth checks if the current collection has "auth" type.
IsBase checks if the current collection has "base" type.
IsNew indicates what type of db query (insert or update) should be used with the model instance.
IsView checks if the current collection has "view" type.
LastSavedPK returns the last saved primary key of the model.
Its value is updated to the latest PK value after MarkAsNotNew() or PostScan() calls.
MarkAsNew clears the pk field and marks the current model as "new" (aka. forces m.IsNew() to be true).
MarkAsNew set the pk field to the Id value and marks the current model as NOT "new" (aka. forces m.IsNew() to be false).
MarshalJSON implements the [json.Marshaler] interface.
Note that non-type related fields are ignored from the serialization (ex. for "view" collections the "auth" fields are skipped).
PostScan implements the [dbx.PostScanner] interface to auto unmarshal the raw serialized options into the concrete type specific fields.
RemoveIndex removes a single index with the specified name from the current collection.
String returns a string representation of the current collection.
TableName returns the Collection model SQL table name.
UnmarshalJSON implements the [json.Unmarshaler] interface.
For new/"blank" Collection models it replaces the model with a factory instance and then unmarshal the provided data one on top of it.
authAlert: AuthAlertConfig
AuthAlert defines options related to the auth alerts on new device login.
Optional authRuleauthRule?: string
AuthRule could be used to specify additional record constraints applied after record authentication and right before returning the auth token response to the client.
For example, to allow only verified users you could set it to "verified = true".
Set it to empty string to allow any Auth collection record to authenticate.
Set it to nil to disallow authentication altogether for the collection (that includes password, OAuth2, etc.).
authToken: TokenConfig
confirmEmailChangeTemplate: EmailTemplate
Optional createRulecreateRule?: string
Optional deleteRuledeleteRule?: string
emailChangeToken: TokenConfig
fields: core.FieldsList
fileToken: TokenConfig
id: string
Id is the primary key of the model. It is usually autogenerated by the parent model implementation.
indexes: JSONArray<string>
Optional listRulelistRule?: string
Optional manageRulemanageRule?: string
ManageRule gives admin-like permissions to allow fully managing the auth record(s), eg. changing the password without requiring to enter the old one, directly updating the verified state and email, etc.
This rule is executed in addition to the Create and Update API rules.
mfa: MFAConfig
MFA defines options related to the Multi-factor authentication (MFA).
name: string
oauth2: OAuth2Config
OAuth2 specifies whether OAuth2 auth is enabled for the collection and which OAuth2 providers are allowed.
otp: OTPConfig
OTP defines options related to the One-time password authentication (OTP).
passwordAuth: PasswordAuthConfig
PasswordAuth defines options related to the collection password authentication.
passwordResetToken: TokenConfig
rawOptions: JSONRaw
RawOptions represents the raw serialized collection option loaded from the DB. NB! This field shouldn't be modified manually. It is automatically updated with the collection type specific option before save.
resetPasswordTemplate: EmailTemplate
system: boolean
System prevents the collection rename, deletion and rules change. It is used primarily for internal purposes for collections like "_superusers", "_externalAuths", etc.
type: "base" | "view" | "auth"
Optional updateRuleupdateRule?: string
verificationTemplate: EmailTemplate
verificationToken: TokenConfig
viewQuery: string
Optional viewRuleviewRule?: string
OSLightDark
Generated using TypeDoc