Relational API Operations
These advanced helper functions are designed to handle CRUD operations on related tables—those nested under a parent component in Supista ERP. Each function requires both the parent record ID (__d3__parentID) and the relation ID (__d3__relationID), which are typically available in the userData object.
- createOpWithRelation
- readOpWithRelation
- updateOpWithRelation
- removeOpWithRelation
- bulkCreateOpWithRelation
createOpWithRelation
Usage:
const createdData = await createOpWithRelation(
tableName,
payload,
__d3__parentID,
__d3__relationID
);tableName: The main table name of the component.payload: Contains the modifieduserDatafor the create request.__d3__parentID: The parent record ID (fromuserData).__d3__relationID: The relation ID identifying the nested table (fromuserData).
Return Value:
Returns the result of Sequelize dataModel.create() — the newly created record.
Sample Output:
{
"id": 1,
"columnName1": "columnValue1",
"columnName2": "columnValue2",
"columnName3": "columnValue3"
}readOpWithRelation
Usage:
const rowsData = await readOpWithRelation(
tableName,
payload,
__d3__parentID,
__d3__relationID
);tableName: The main table name of the component.payload: Contains the modifieduserDatafor the read request.__d3__parentID: Parent record ID.__d3__relationID: Child relation ID.
Return Value:
Returns the result of Sequelize dataModel.findAndCountAll() — includes total count and matched rows.
Sample Output:
{
"count": 1,
"rows": [
{
"id": 1,
"columnName1": "columnValue1",
"columnName2": "columnValue2",
"columnName3": "columnValue3"
}
]
}updateOpWithRelation
Usage:
const updatedData = await updateOpWithRelation(
tableName,
payload,
__d3__parentID,
__d3__relationID
);tableName: The main table name of the component.payload: Contains the modifieduserDatafor the update request.__d3__parentID: Parent record ID.__d3__relationID: Child relation ID.
Return Value:
Returns the result of Sequelize dataModel.update() — indicates number of records affected.
Sample Output:
{
"affectedCount": [1]
}removeOpWithRelation
Usage:
const deletedData = await removeOpWithRelation(
tableName,
payload,
__d3__parentID,
__d3__relationID
);tableName: The main table name of the component.payload: Contains__d3__idor equivalent in the request.__d3__parentID: Parent record ID.__d3__relationID: Child relation ID.
Return Value:
Returns the result of Sequelize dataModel.delete() — count of deleted rows.
Sample Output:
{
"deletedObjNo": 1
}bulkCreateOpWithRelation
Usage:
const bulkData = await bulkCreateOpWithRelation(
tableName,
payload,
__d3__parentID,
__d3__relationID
);tableName: The main table name of the component.payload: Contains__d3__bulkData— an array of records.__d3__parentID: Parent record ID.__d3__relationID: Child relation ID.
Example Payload:
{
"__d3__bulkData": [
{
"columnName1": "columnValue1",
"columnName2": "columnValue2",
"columnName3": "columnValue3"
},
{
"columnName1": "columnValue1",
"columnName2": "columnValue2",
"columnName3": "columnValue3"
}
]
}Ensure
__d3__parentIDand__d3__relationIDare passed along with the payload to maintain relational integrity.
Return Value:
Returns an array of inserted records using Sequelize dataModel.bulkCreate().
Sample Output:
[
{
"columnName1": "columnValue1",
"columnName2": "columnValue2",
"columnName3": "columnValue3"
},
{
"columnName1": "columnValue1",
"columnName2": "columnValue2",
"columnName3": "columnValue3"
}
]