Quick background: I'm still a pretty much total newbie at cakePHP, but
I've been coding websites in PHP, ASP, Java, and Perl for 10 years.
I've recently started on a cakePHP project and things are going
relatively well, if extremely slowly. I could have completed the whole
project by now using PHP and a home rolled template system, but I'm
still hoping some efficiency payoffs will come once I'm less of a noob.

My current problem is this:
I have a model, Category.  Each Category hasMany Category, like this:
------------
var $hasMany = array('subcats' =>
                                                array('className'    => 
'Category',
                                                          'conditions'   => '',
                                                          'order'        => '',
                                                          'foreignKey'   => 
'parent_id'
                                                         )
                  );
-------------

What I am trying to do is to ONLY allow a Category to be deleted if it
has no child categories.

I found an example which basically answers this very problem here:
http://othy.wordpress.com/2006/05/30/restrict-a-record-from-deletion-if-it-has-associated-records/

However, if I try and write a function like that for my code, and put
it in my Category.php model file:

-------------
function beforeDelete($id) {
        if($this->Category->hasAny(array('>Category.parent_id'=> $id))) {
                return false;
        }
        return true;
}
------------

All I get is this message in the browser:
"Missing argument 1 for beforedelete() " -- meaning, I presume, the $id
isn't getting passed to my beforeDelete function. Is this supposed to
be automatic (it's certainly passed to the del())?

Any advice on how to make this work would be greatly appreciated.

Thanks!


--~--~---------~--~----~------------~-------~--~----~
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