Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:40:47+00:00 2026-05-15T13:40:47+00:00

My situation may be a bit abnormal, but I have foreign keys defined in

  • 0

My situation may be a bit abnormal, but I have foreign keys defined in my MySQL database, while enforcing referential integrity in the Zend_Db_Table classes. The tables use the InnoDB storage engine.

When deleting a record, the Zend Framework will properly identify immediate children via the $_referenceMap in the table model and delete them. However, if there are any children of the immediate child, I am getting an error back from the database about violating the referential integrity of that foreign key: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails. It seems that the Zend_Db_Table_Abstract doesn’t enforce referential integrity in a recursive fashion.

Has anyone else encountered this? Is it a Zend Framework bug? Workarounds? Fixes?


UPDATE

Nearly a week later and I have no replies to this question. I am thinking I’ll have to extend the Zend_Db_Table_Row_Abstract class myself to accomplish this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:40:48+00:00Added an answer on May 15, 2026 at 1:40 pm

    I ended up extending the Zend_Db_Table_Abstract class to accomplish this. The _cascadeDelete public function makes a call to the database adapter delete function. I made changes so that the delete function from Zend_Db_Table_Row_Abstract gets called instead. This makes record deletions recursive.

    UPDATE: I have added code for when on delete is set to self::SET_NULL.

    Here’s my modified version of _cascadeDelete:

    /**
     * Called by parent table's class during delete() method.
     *
     * @param  string $parentTableClassname
     * @param  array  $primaryKey
     * @return int    Number of affected rows
     */
    public function _cascadeDelete($parentTableClassname, array $primaryKey)
    {
        $this->_setupMetadata();
        $rowsAffected = 0;
        foreach ($this->_getReferenceMapNormalized() as $map) {
            if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) {
                switch ($map[self::ON_DELETE]) {
                    case self::CASCADE:
                        $select = $this->select();
                        for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
                            $col = $this->_db->foldCase($map[self::COLUMNS][$i]);
                            $refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]);
                            $type = $this->_metadata[$col]['DATA_TYPE'];
                            $select->where($this->_db->quoteIdentifier($col, true) . ' = ?',
                                $primaryKey[$refCol], $type);
                        }
                        $rows = $this->fetchAll($select);
                        $rowsAffected += count($rows);
                        foreach ($rows as $row) {
                            $row->delete();
                        }
                        break;
                    case self::SET_NULL: {
                        $update = array();
                        $where = array();
                        for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
                            $col = $this->_db->foldCase($map[self::COLUMNS][$i]);
                            $refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]);
                            $type = $this->_metadata[$col]['DATA_TYPE'];
                            $update[$col] = null;
                            $where[] = $this->_db->quoteInto(
                                $this->_db->quoteIdentifier($col, true) . ' = ?',
                                $primaryKey[$refCol], $type);
                        }
                        $rowsAffected += $this->update($update, $where);
                        break;
                    }
                    default:
                        // no action
                        break;
                }
            }
        }
        return $rowsAffected;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a few questions bundled into one, but here is the situation.
I'm using the Rails gem SimpleForm, but I think my question may be applicable
I have a database of user submitted latitude/longitude points and am trying to group
Here's my problem. I have three controls in a row (they capture people's names).
I have approached you today to try and gather your opinions and experience with
This is one of those problems that is a bit vague and so difficult
I'm trying to serialize a pointer to a polymorphic class Shape . So I
I want to develop a tool that does the following things. take in a
I'm trying to come up with a reusable warning piece for the business objects
The Delphi debugger is great for debugging linear code, where one function calls other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.