src/Data/BizDataObj.php
protected function processCascadeAction($objRef, $cascadeType)
    {
        if (($cascadeType == 'Delete' && $objRef->onDelete) || ($cascadeType == 'Update' && $objRef->onUpdate)) {
            if ($objRef->relationship == "1-M" || $objRef->relationship == "1-1") {
                $table = $objRef->table;
                $column = $objRef->column;
                $column2 = $objRef->column2;
            } else if ($objRef->relationship == "M-M" || $objRef->relationship == "Self-Self") {
                $table = $objRef->xTable;
                $column = $objRef->xColumn1;
            }
            $refField = $this->getField($objRef->fieldRef);
            $fieldVal = $this->getFieldValue($objRef->fieldRef);

            $fieldVal2 = $this->getFieldValue($objRef->fieldRef2);
            if (!$fieldVal)
                return;
            if ($column2) {
                if (!$fieldVal2)
                    return;
            }

            $db = $this->getDBConnection("WRITE");
            // get the cascade action sql
            if ($cascadeType == 'Delete') {
                if ($objRef->onDelete == "Cascade") {
                    $sql = "DELETE FROM " . $table . " WHERE " . $column . "='" . $fieldVal . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onDelete == "SetNull") {
                    $sql = "UPDATE " . $table . " SET $column=null WHERE " . $column . "='" . $fieldVal . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onDelete == "Restrict") {
                    // check if objRef has records
                    $refObj = $this->getRefObject($objRef->objectName);
                    $sql = "`$column`='" . $refField->value . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                    if (count($refObj->directFetch($sql, 1)) == 1) {
                        throw new Openbizx\Data\Exception($this->getMessage("DATA_UNABLE_DEL_REC_CASCADE", array($objRef->objectName)));
                    }
                    return;
                }
            } else if ($cascadeType == 'Update') {
                // check if the column value is actually changed
                if ($refField->oldValue == $refField->value)
                    return;

                if ($objRef->onUpdate == "Cascade") {
                    $sql = "UPDATE " . $table . " SET $column='" . $refField->value . "' WHERE " . $column . "='" . $refField->oldValue . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onUpdate == "SetNull") {
                    $sql = "UPDATE " . $table . " SET $column=null WHERE " . $column . "='" . $refField->oldValue . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onUpdate == "Restrict") {
                    // check if objRef has records
                    $refObj = Openbizx::getObject($objRef->objectName);
                    $sql = "[" . $objRef->fieldRef . "]='" . $refField->oldValue . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                    if (count($refObj->directFetch($sql, 1)) == 1) {
                        throw new Openbizx\Data\Exception($this->getMessage("DATA_UNABLE_UPD_REC_CASCADE", array($objRef->objectName)));
                    }
                    return;
                }
            }
            try {
                Openbizx::$app->getLog()->log(LOG_DEBUG, "DATAOBJ", "Cascade $cascadeType Sql = $sql");
                $db->query($sql);
            } catch (Exception $e) {
                Openbizx::$app->getLog()->log(LOG_Err, "DATAOBJ", "Cascade $cascadeType Error: " . $e->getMessage());
                $this->errorMessage = $this->getMessage("DATA_ERROR_QUERY") . ": " . $sql . ". " . $e->getMessage();
                throw new Openbizx\Data\Exception($this->errorMessage);
            }
        }
    }
protected function processCascadeAction($objRef, $cascadeType)
    {
        if (($cascadeType == 'Delete' && $objRef->onDelete) || ($cascadeType == 'Update' && $objRef->onUpdate)) {
            if ($objRef->relationship == "1-M" || $objRef->relationship == "1-1") {
                $table = $objRef->table;
                $column = $objRef->column;
                $column2 = $objRef->column2;
            } else if ($objRef->relationship == "M-M" || $objRef->relationship == "Self-Self") {
                $table = $objRef->xTable;
                $column = $objRef->xColumn1;
            }
            $refField = $this->getField($objRef->fieldRef);
            $fieldVal = $this->getFieldValue($objRef->fieldRef);

            $fieldVal2 = $this->getFieldValue($objRef->fieldRef2);
            if (!$fieldVal)
                return;
            if ($column2) {
                if (!$fieldVal2)
                    return;
            }

            $db = $this->getDBConnection("WRITE");
            // get the cascade action sql
            if ($cascadeType == 'Delete') {
                if ($objRef->onDelete == "Cascade") {
                    $sql = "DELETE FROM " . $table . " WHERE " . $column . "='" . $fieldVal . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onDelete == "SetNull") {
                    $sql = "UPDATE " . $table . " SET $column=null WHERE " . $column . "='" . $fieldVal . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onDelete == "Restrict") {
                    // check if objRef has records
                    $refObj = $this->getRefObject($objRef->objectName);
                    $sql = "`$column`='" . $refField->value . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                    if (count($refObj->directFetch($sql, 1)) == 1) {
                        throw new Openbizx\Data\Exception($this->getMessage("DATA_UNABLE_DEL_REC_CASCADE", array($objRef->objectName)));
                    }
                    return;
                }
            } else if ($cascadeType == 'Update') {
                // check if the column value is actually changed
                if ($refField->oldValue == $refField->value)
                    return;

                if ($objRef->onUpdate == "Cascade") {
                    $sql = "UPDATE " . $table . " SET $column='" . $refField->value . "' WHERE " . $column . "='" . $refField->oldValue . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onUpdate == "SetNull") {
                    $sql = "UPDATE " . $table . " SET $column=null WHERE " . $column . "='" . $refField->oldValue . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                } else if ($objRef->onUpdate == "Restrict") {
                    // check if objRef has records
                    $refObj = Openbizx::getObject($objRef->objectName);
                    $sql = "[" . $objRef->fieldRef . "]='" . $refField->oldValue . "'";
                    if ($column2 && $fieldVal2) {
                        $sql .= " AND " . $column2 . "='" . $fieldVal2 . "'";
                    }
                    if (count($refObj->directFetch($sql, 1)) == 1) {
                        throw new Openbizx\Data\Exception($this->getMessage("DATA_UNABLE_UPD_REC_CASCADE", array($objRef->objectName)));
                    }
                    return;
                }
            }
            try {
                Openbizx::$app->getLog()->log(LOG_DEBUG, "DATAOBJ", "Cascade $cascadeType Sql = $sql");
                $db->query($sql);
            } catch (Exception $e) {
                Openbizx::$app->getLog()->log(LOG_Err, "DATAOBJ", "Cascade $cascadeType Error: " . $e->getMessage());
                $this->errorMessage = $this->getMessage("DATA_ERROR_QUERY") . ": " . $sql . ". " . $e->getMessage();
                throw new Openbizx\Data\Exception($this->errorMessage);
            }
        }
    }
$action: Delete, Update