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 8224713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:10:00+00:00 2026-06-07T15:10:00+00:00

Good afternooon everyone, i’ll go straight to the point. I have this code at

  • 0

Good afternooon everyone, i’ll go straight to the point. I have this code at my model:

protected $_referenceMap = Array (
    "Imagens" => Array(
        "columns"       => Array (
            'paiId'
        ),
        "refTableClass" => "ModeloImagem",
        "refColumns"    => Array(
            "id"
        ),
        "onDelete" => self::CASCADE
    )
);

I must delete the images on the table that’s going to be called on cascade, so i wanted to know if is there something like:

protected $_referenceMap = Array (
    "Imagens" => Array(
        "columns"       => Array (
            'paiId'
        ),
        "refTableClass" => "ModeloImagem",
        "refColumns"    => Array(
            "id"
        ),
        "onDelete" => function() {
            foreach($image as $i) {
                unlink($i);
            }
            return self::CASCADE
        }
    )
);
  • 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-06-07T15:10:01+00:00Added an answer on June 7, 2026 at 3:10 pm

    There is no such thing. What you can do is extend Zend_Db_Table’s method _cascadeDelete($parentTableClassname, array $primaryKey) to execute the function.

    Here’s one way to do it, although it’s a terrible amount of code duplication; you might have to specify your own data that you want to be passed to the callback, or modify behavior depending on whether your callback or query fails:

    class My_Db_Table extends Zend_Db_Table
    {
        const ON_DELETE_CALLBACK = 'onDeleteCallback';
    
        /**
         * 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)
        {
            $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:
                            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'];
                                $where[] = $this->_db->quoteInto(
                                    $this->_db->quoteIdentifier($col, true) . ' = ?',
                                    $primaryKey[$refCol], $type);
                            }
                            $this->_executeCallback($map, $where);
                            $rowsAffected += $this->delete($where);
                            break;
                        default:
                            // no action
                            break;
                    }
                }
            }
            return $rowsAffected;
        }
    
        private function _executeCallback($map, $where) {
            if (isset($map[self::ON_DELETE_CALLBACK]) && is_callable($map[self::ON_DELETE_CALLBACK])) {
                call_user_func($map[self::ON_DELETE_CALLBACK], $where);
            }
        }
    }
    

    You then use this to define the callback function. You can’t define cascade in callback function though; else all your images get deleted every time Zend_Db_Table tries to figure out whether to delete entries from images table.

    protected $_referenceMap = Array (
        "Images" => Array(
            "columns"       => Array (
                'paiId'
            ),
            "refTableClass" => "ModeloImagem",
            "refColumns"    => Array(
                "id"
            ),
            "onDelete" => self::CASCADE,
            "onDeleteCallback" => function($where) {
                // Determine which image to unlink
                unlink($image);
            }
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Afternoon, everyone. I have an ongoing issue with the code below. I know
Good afternoon to all, I have this scenario: I am using SQL Server 'BulkInsert'
Good afternoon everybody! I have this threaded SerialPort wrapper that reads in a line
Good afternoon everyone. I was wondering if there is anyway to have the MVC
Good afternoon. I have an array with some keys, and values in them. I
Good afternoon, I inherited some C# code from years ago. I have refactored it
Good Afternoon all , I have downloaded data from a web service and im
Good afternoon I'm hoping this is going to be nice and a simple f**k
Good afternoon, I'm having a problem with a section of code I'm working on
Good afternoon, I have a quick 'top level' question regarding the usage of Facebook

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.