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.

  1. createOpWithRelation
  2. readOpWithRelation
  3. updateOpWithRelation
  4. removeOpWithRelation
  5. bulkCreateOpWithRelation

createOpWithRelation

Usage:

const createdData = await createOpWithRelation(
  tableName,
  payload,
  __d3__parentID,
  __d3__relationID
);
  • tableName: The main table name of the component.
  • payload: Contains the modified userData for the create request.
  • __d3__parentID: The parent record ID (from userData).
  • __d3__relationID: The relation ID identifying the nested table (from userData).

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 modified userData for 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 modified userData for 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__id or 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__parentID and __d3__relationID are 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"
  }
]
Last updated on
Transform Data into Decisions with Supista – Your Intelligent Data Partner
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Cookie Policy. Learn More.