Hi, I got this thing corrected. The function delete($id) from the model
should be removed. Instead, the statements inside this function should be
written in the corresponding controller.
e.g

class ContestsController extends Zend_Controller_Action 
{
        function deleteAction()
        {
                $model = new Contests(Zend_Registry::get('db'));
            $rowset = $model->find($this->getRequest()->getParam('id'));
            $current = $rowset->current();
            $current->delete();
            $this->_redirect($_SERVER['HTTP_REFERER']);
        }
}

This is what  I followed and everything is working fine. Could also be name
collision as stated by PHPScriptor.

Thanks,
Vibhor

-----Original Message-----
From: PHPScriptor [mailto:[email protected]] 
Sent: Friday, February 20, 2009 10:08 PM
To: [email protected]
Subject: Re: [fw-general] Child rows get deleted but Parent does not


try to call the delete function in your model something else, like
deletebyid($id)... 


Vibhor Singh-2 wrote:
> 
> Hi all,
> 
> I have implemented a one-to-many relationship between 2 tables (contests,
> contest_winners)
> 
> One contest can have many contest_winners
> 
> The problem is that when I delete a contest, the child records get deleted
> but the parent record does not. It gives the following error:
> 
> Fatal error: Call to a member function delete() on a non-object in /..
> /application/models/Contests.php.
> 
> This is how I have written the individual classes:
> 
> class Contests extends Zend_Db_Table_Abstract 
> {
>             protected $_name      = 'contests';
>             protected $_dependentTables = array('ContestWinners');
> 
>       function delete($id)
>       {
>           $rowset = $this->find($id);
>           $current = $rowset->current();
>           $current->delete();
>           return true; 
>       }
> }
> 
> class ContestWinners extends Zend_Db_Table_Abstract
> {
>             protected $_name      = 'contest_winners';
>             protected $_referenceMap    = array(
>                             'Winners' => array(
>                                 'columns'           =>
> array('contests_id'),
> //can some one please tell me why we use array here?
> 
>                                 'refTableClass'     => 'Contests',
> 
>                                 'refColumns'        => array(id'),
> //and here
> 
>                                 'onDelete'          => self::CASCADE
> 
>         ));
> 
>  
> 
> }
> 
>  
> 
> Can anyone please look into this?
> Any help would be appreciated. Thanks,
> 
>  
> 
> Vibhor
> 


-----
visit my website at  http://www.phpscriptor.com/ http://www.phpscriptor.com/

-- 
View this message in context:
http://www.nabble.com/Child-rows-get-deleted-but-Parent-does-not-tp22120306p
22121297.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Reply via email to