getDependentTables example

/** * Were any of the changed columns part of the primary key? */
        $pkDiffData = array_intersect_key($diffDataarray_flip((array)$this->_primary));

        /** * Execute cascading updates against dependent tables. * Do this only if primary key value(s) were changed. */
        if (count($pkDiffData) > 0) {
            $depTables = $this->_getTable()->getDependentTables();
            if (!empty($depTables)) {
                $pkNew = $this->_getPrimaryKey(true);
                $pkOld = $this->_getPrimaryKey(false);
                foreach ($depTables as $tableClass) {
                    $t = $this->_getTableFromString($tableClass);
                    $t->_cascadeUpdate($this->getTableClass()$pkOld$pkNew);
                }
            }
        }

        /** * Execute the UPDATE (this may throw an exception) * Do this only if data values were changed. * Use the $diffData variable, so the UPDATE statement * includes SET terms only for data values that changed. */
return $rowsAffected;
    }

    /** * Deletes existing rows. * * @param array|string $where SQL WHERE clause(s). * @return int The number of rows deleted. */
    public function delete($where)
    {
        $depTables = $this->getDependentTables();
        if (!empty($depTables)) {
            $resultSet = $this->fetchAll($where);
            if (count($resultSet) > 0 ) {
                foreach ($resultSet as $row) {
                    /** * Execute cascading deletes against dependent tables */
                    foreach ($depTables as $tableClass) {
                        $t = self::getTableFromString($tableClass$this);
                        $t->_cascadeDelete($tableClass$row->getPrimaryKey());
                    }
                }
Home | Imprint | This part of the site doesn't use cookies.