src/Data/Tools/BizDataObj_Assoc.php
private static function _addRecordMtoM($dataObj, $recArr)
    {
        // query on this object to get the corresponding record of this object.
        $searchRule = "[Id] = '" . $recArr["Id"] . "'";
        $recordList = $dataObj->directFetch($searchRule, 1);
        if (count($recordList) == 1) {
            return true;
        }

        // insert a record on XTable
        $db = $dataObj->getDBConnection();
        $xDataObj = isset($dataObj->association["XDataObj"]) ? $dataObj->association["XDataObj"] : null;
        $val1 = $dataObj->association["FieldRefVal"];
        $val2 = $recArr["Id"];
        if ($xDataObj) {   // get new record from XDataObj
            $xObj = Openbizx::getObject($xDataObj);
            $newRecArr = $xObj->newRecord();
            // verify the main table of XDataobj is same as the XTable
            if ($xObj->mainTableName != $dataObj->association["XTable"]) {
                throw new Openbizx\Data\Exception("Unable to create a record in intersection table: XDataObj's main table is not same as XTable.");
                //return false;
            }
            $fld1 = $xObj->getFieldNameByColumn($dataObj->association["XColumn1"]);
            $newRecArr[$fld1] = $val1;
            $fld2 = $xObj->getFieldNameByColumn($dataObj->association["XColumn2"]);
            $newRecArr[$fld2] = $val2;
            $ok = $xObj->insertRecord($newRecArr);
            if ($ok === false) {
                throw new Openbizx\Data\Exception($xObj->getErrorMessage());
                //return false;
            }
        } else {
            $sql_col = "(" . $dataObj->association["XColumn1"] . ","
                    . $dataObj->association["XColumn2"] . ")";

            $sql_val = "('" . $val1 . "','" . $val2 . "')";
            $sql = "INSERT INTO " . $dataObj->association["XTable"] . " "
                    . $sql_col . " VALUES " . $sql_val;

            try {
                Openbizx::$app->getLog()->log(LOG_DEBUG, "DATAOBJ", "Associate Insert Sql = $sql");
                $db->query($sql);
            } catch (Exception $e) {
                Openbizx::$app->getLog()->log(LOG_ERR, "DATAOBJ", "Query Error: " . $e->getMessage());
                throw new Openbizx\Data\Exception("Query Error: " . $e->getMessage());
                return false;
            }
        }

        // add the record to object cache. requery on this object to get the corresponding record of this object.
        $searchRule = "[Id] = '" . $recArr["Id"] . "'";
        $recordList = $dataObj->directFetch($searchRule, 1);
        if (count($recordList) == 0)
            return false;
        return true;
    }
private static function _addRecordMtoM($dataObj, $recArr)
    {
        // query on this object to get the corresponding record of this object.
        $searchRule = "[Id] = '" . $recArr["Id"] . "'";
        $recordList = $dataObj->directFetch($searchRule, 1);
        if (count($recordList) == 1) {
            return true;
        }

        // insert a record on XTable
        $db = $dataObj->getDBConnection();
        $xDataObj = isset($dataObj->association["XDataObj"]) ? $dataObj->association["XDataObj"] : null;
        $val1 = $dataObj->association["FieldRefVal"];
        $val2 = $recArr["Id"];
        if ($xDataObj) {   // get new record from XDataObj
            $xObj = Openbizx::getObject($xDataObj);
            $newRecArr = $xObj->newRecord();
            // verify the main table of XDataobj is same as the XTable
            if ($xObj->mainTableName != $dataObj->association["XTable"]) {
                throw new Openbizx\Data\Exception("Unable to create a record in intersection table: XDataObj's main table is not same as XTable.");
                //return false;
            }
            $fld1 = $xObj->getFieldNameByColumn($dataObj->association["XColumn1"]);
            $newRecArr[$fld1] = $val1;
            $fld2 = $xObj->getFieldNameByColumn($dataObj->association["XColumn2"]);
            $newRecArr[$fld2] = $val2;
            $ok = $xObj->insertRecord($newRecArr);
            if ($ok === false) {
                throw new Openbizx\Data\Exception($xObj->getErrorMessage());
                //return false;
            }
        } else {
            $sql_col = "(" . $dataObj->association["XColumn1"] . ","
                    . $dataObj->association["XColumn2"] . ")";

            $sql_val = "('" . $val1 . "','" . $val2 . "')";
            $sql = "INSERT INTO " . $dataObj->association["XTable"] . " "
                    . $sql_col . " VALUES " . $sql_val;

            try {
                Openbizx::$app->getLog()->log(LOG_DEBUG, "DATAOBJ", "Associate Insert Sql = $sql");
                $db->query($sql);
            } catch (Exception $e) {
                Openbizx::$app->getLog()->log(LOG_ERR, "DATAOBJ", "Query Error: " . $e->getMessage());
                throw new Openbizx\Data\Exception("Query Error: " . $e->getMessage());
                return false;
            }
        }

        // add the record to object cache. requery on this object to get the corresponding record of this object.
        $searchRule = "[Id] = '" . $recArr["Id"] . "'";
        $recordList = $dataObj->directFetch($searchRule, 1);
        if (count($recordList) == 0)
            return false;
        return true;
    }
Add record many to many (M-M)

@param BizDataObj $dataObj
@param array $recArr
@return boolean