Hi all,

I have a method which loops through an array of ids and deletes the
corresponding Note record.  Upon deleting, it also checks whether the
associated Document is still associated with other Notes.  If it
isn't, it should be deleted.

The problem I'm having is that even though I am calling a find each
time through the foreach loop, it doesn't seem to be updating.  So if
I have 3 Notes with the same document associated, the first time
through the loop the $doc array shows 2 Notes associated (because the
first was deleted) but then the second and third times through it
still shows the same 2 Notes associated even after they are deleted.

Am I missing something or is this a known behavior of Cake?  Thanks
for any help and let me know if this doesn't make sense.

[code]
function deletecn($boxname = null){
                //data array contains cn id #'s as the values
                $cns = $this->data;
                if (!empty($cns)){
                        $unique_cns = array_unique($cns);
                        foreach ($unique_cns as $id){
                                $mycn = $this->Account->Note->read(null, $id);
                                if ($this->Account->Note->del($id)) {
                                        //now want to search to see if the 
document is still associated
with any Notes.  If not, delete the entry from the Document table.
                                        $doc_id = $mycn['Document']['id'];
                                        if (!empty($doc_id)){
                                                $doc = 
$this->Account->Note->Document->findById($doc_id);
                                                if (empty($doc['Note'])){
                                                        
$this->Account->Note->Document->del($doc_id);
                                                        $this->log("document 
with id = $doc_id was deleted
successfully", LOG_DEBUG);
                                                }else{
                                                        $this->log("document 
with id = $doc_id is still in use and was
not deleted", LOG_DEBUG);
                                                }

                                        }
                                }
                        }//end foreach
                }
                $this->redirect("/accounts/index");
        }
[/code]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to