# new Record(recordDataopt, inheritopt) → {object}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
recordData |
object
|
<optional> |
Optional data used to create the record |
inherit |
boolean
|
<optional> |
If true, create a blank record then assign recordData to it |
Record
object
Example
// Get the "user" model
const userModel = kiss.app.models.user
// Create a new user instance
const myUser = userModel.create({
firstName: "Bob",
lastName: "Wilson",
email: "bob.wilson@gmail.com"
})
// Save the new record
await myUser.save()
// Call custom model's method
myUser.sendEmail({
subject: "Hello ${myContact.firstName}",
message: "How are you?"
})
// Update the record
await myUser.update({
firstName: "Bobby"
})
// Delete the record
await myUser.delete()
Methods
# async checkPermission(action) → {boolean}
Check the permission (client-side) to perform an action on the record.
Parameters:
Name | Type | Description |
---|---|---|
action |
string
|
"update" | "delete" |
true if the permission is granted
boolean
# async checkValidationRules(fieldId, value) → {boolean}
Check the validation rules of a field if they exist
Parameters:
Name | Type | Description |
---|---|---|
fieldId |
string
|
|
value |
*
|
true if the value is valid or if there is no validation rule
boolean
# async delete(sendToTrashopt) → {boolean}
Delete the record from the database
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
sendToTrash |
boolean
|
<optional> |
If true, keeps the original record in a "trash" collection. Default = false |
true if deleted successfuly
boolean
Example
await myTask.delete()
# async getData(config, skipIdsopt, accountIdopt) → {object}
Get the data and populate the fields linked to foreign records.
The function is recursive and explore all the records connections. To avoid endless loops, each model that has already been explored is "skipped" from inner exploration. In a future evolution, we may also allow exploration of the same model in inner exploration, but limiting it to a predefined depth.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
pbject
|
||
useLabels |
boolean
|
<optional> |
If true, use labels as exported keys. Default to false |
convertNames |
boolean
|
<optional> |
If true, convert emails and groups ids to directory names |
numberAsText |
boolean
|
<optional> |
If true, convert numbers to text with fixed number of digits according to the defined precision. Default to false |
includeLinks |
boolean
|
<optional> |
If true, explore links and includes them as nested data. Default to false |
linksDepth |
number
|
<optional> |
Maximum depth when exploring the links. Default to 1, meaning it only gets the direct relationships. |
sortLinks |
boolean
|
<optional> |
If true, check if the links have been sorted by the user. Default to false |
projection |
Array.<string>
|
<optional> |
Keep only the fields specified in this array. All fields by default. |
skipIds |
Array.<string>
|
<optional> |
Model ids to skip in the exploration of nested data |
accountId |
string
|
<optional> |
For server only: accountId allows to retrieve the right directory to merge directory fields |
Record's data, like: {a: 1, b: 2}
object
Example
myRecord.getData() // {"aEf32x": "Bob", "e07d58": "Wilson"}
myRecord.getData({useLabels: true}) // {"First name": "Bob", "Last name": "Wilson"}
# getFiles() → {Array.<object>}
Get the files attached to the record
The list of file objects
Array.<object>
Example
[
{
"id": "dbba41cc-6ec6-4bb9-981a-4e27eafb20b9",
"filename": "logo 8.png",
"path": "https://pickaform-europe.s3.eu-west-3.amazonaws.com/files/a50616e1-8cce-4788-ae4e-7ee10d35b5f2/2022/06/17/logo%208.png",
"size": 7092,
"type": "amazon_s3",
"mimeType": "image/png",
"thumbnails": {
// Thumbnails infos
},
"createdAt": "2022-06-16T20:49:29.349Z",
"createdBy": "john.doe@pickaform.com"
},
{
"id": "0185c4f3-e3ff-7933-a1f2-e06459111665",
"filename": "France invest.PNG",
"path": "uploads\\01847546-a751-7a6e-9e6a-42b8b8e37570\\2023\\01\\18\\France invest.PNG",
"size": 75999,
"type": "local",
"mimeType": "image/png",
"thumbnails": {
// Thumbnails infos
},
"createdAt": "2023-01-18T12:56:36.095Z",
"createdBy": "georges.lucas@pickaform.com"
}
]
# getSanitizedData() → {object}
Get the record's sanitized data to keep only the model's fields
The sanitized data
object
# hasChanged(dataopt) → {boolean}
Check if the record has changed since its last state
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
object
|
<optional> |
Optional data to compare |
boolean
# async read()
Get the record's data from the database and update the record's instance. It guaranties to get the last version of the record locally in case it was updated remotely.
this
Example
console.log(user) // Bob Wilson
await user.read()
console.log(user) // Bob WILSON JR
# async save() → {boolean}
Save a record in the database
true if successfuly created, false otherwise
boolean
Example
let newUser = userModel.create({firstName: "Bob", lastName: "Wilson"})
await newUser.save() // Insert the record into the database
newUser.lastName = "SMITH" // Update a property
await newUser.update() // Update the existing record according to the new data
await newUser.update({lastName: "JONES"}) // Explicit update of the lastName (same as above)
# async update(updateopt, silentopt) → {boolean}
Update the record in the database TODO: apply data validation
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
update |
object
|
<optional> |
Optional update. If not specified, updates all the fields. |
silent |
boolean
|
<optional> |
Set to true to hide the loading spinner (update in the background) |
true if updated successfuly
boolean
Example
await myTask.update({status: "done"})
// Will work too but not optimal because it will save the whole record
myTask.status = "done"
await myTask.update()
# async updateDeep(fieldId, value, transaction) → {boolean}
Update multiple fields
This update propagates other mutations inside the same record and also in foreign records
Parameters:
Name | Type | Description |
---|---|---|
fieldId |
string
|
|
value |
*
|
|
transaction |
object
|
The global Transaction object that contains all the database mutations to perform at once |
true if the field was updated successfuly
boolean
Example
await user.updateDeep({
fistName: "Bob",
lastName: "Wilson"
})
# async updateFieldDeep(fieldId, value) → {boolean}
Update a single field of the record
This update propagates other mutations inside the same record and also in foreign records. It also check the new field value against custom validation function, if it exists.
Parameters:
Name | Type | Description |
---|---|---|
fieldId |
string
|
|
value |
*
|
true if the field was updated successfuly
boolean
Example
await user.updateFieldDeep("lastName", "Wilson")