This may help too - I sort of accidentally stumbled on to this method
while I was working on a project with this thread in mind:

<?php

class User extends AppModel
{
        var $name = 'User';


        function bindComment ($conditions = null, $order = 'created DESC',
$limit = null, $page = '1')
        {
                $this->bindModel(array(
                        'hasMany' => array(
                                'Comment' => array(
                                        'className' => 'Comment',
                                        'conditions' => $conditions,
                                        'order' => $order,
                                        'limit' => $limit,
                                        'foreignKey' => 'user_id',
                                        'dependent' => true,
                                        'exclusive' => false,
                                        'finderSql' => '',
                                        'counterSql' => ''
                                )
                        )
                ));
        }

        function beforeDelete()
        {
                if(parent::beforeDelete())
                {
                        // attach comment model to user so all user's comments 
get wiped on
->del
                        $this->bindComment();

                        return true;
                }
        }

}

?>

Basically now, no matter where a "User" is deleted from, it will bind
the Comments model as "dependent" beforehand, and then delete all
Comments associated with the User being removed.  This way I don't
always have to have Comments bound to my User, but where I do want user
comments, I can say $User->bindComment();


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to